SlideShare una empresa de Scribd logo
1 de 13
Linked Open Data for Rubyists


    What the Semantic Web brings to Ruby

               Gregg Kellogg
              gregg@greggkellogg.net
                Twitter: @gkellogg
                 G+: greggkellogg
Why RDF for Ruby?


   ✤ Major creative force in Web 2.0
   ✤ Rich eco-system (Gems/Rails/…)
   ✤ Fair support for XML (Nokogiri, anyway)
   ✤ Great environment for prototyping and getting
     stuff done.
   ✤ RDF is relatively virgin territory in Ruby



6 Dec 2012                  Ruby SemWeb              2
Ruby RDF
 ❖ RDF.rb/linkeddata                  ❖ Storage
 ❖ Readers/Writers                          ➡ Cassandra

       ➡ RDF/XML                            ➡ SQL(RDF::DO)

       ➡ N3/Turtle/NTriples                 ➡ MongoDB

       ➡ NQuads/TriX                        ➡ Redstore

       ➡ RDFa/Microdata                     ➡ Sesame

       ➡ JSON-LD/RDF-JSON                   ➡ AlegroGraph

       ➡ Raptor bridge                      ➡ Talis
                                            ➡ 4store
 ❖ Query
       ➡ SPARQL/SSE
       ➡ SPARQL::Client


6 Dec 2012                    Ruby SemWeb                    3
Core Classes
 ❖ RDF::Term                                  ❖ Serializations
       ➡ RDF::Literal                               ➡ RDF::Format
             ➡ XSD subtypes                         ➡ RDF::Reader
       ➡ RDF::Resource                              ➡ RDF::Writer
             ➡ RDF::Node                      ❖ Storage
             ➡ RDF::URI                             ➡ RDF::Repository
             ➡ RDF::List
                                              ❖ Query
             ➡ RDF::Graph
                                                    ➡ RDF::Query
 ❖ RDF::Statement                                   ➡ RDF::Query::Pattern
 ❖ RDF::Vocabulary                                  ➡ RDF::Query::Solution
       ➡ With definitions for common                 ➡ RDF::Query::Variable
         vocabularies

6 Dec 2012                            Ruby SemWeb                            4
Simple Graph Manipulation
require 'rdf'

include RDF
g = Graph.new
g << Statement.new(
  RDF::URI.new("https://github.com/gkellogg/rdf"),
  RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
  RDF::URI.new("http://usefulinc.com/ns/doap#GitRepository"))

# Using common vocabularies
proj = Node.new
g << Statement.new(proj, RDF.type, DOAP.Project)
g << Statement.new(proj, DOAP.repository,
  RDF::URI.new("https://github.com/gkellogg/rdf"))

puts g.dump(:ntriples)




6 Dec 2012                     Ruby SemWeb                           5
Serializing with Writers
   ✤ Graphs can be serialized with available Writers

require 'rdf/ntriples'
require 'rdf/turtle'

puts NTriples::Writer.buffer {|writer| writer << g}

# Also, you can include other formats
Turtle::Writer.buffer {|writer| writer << g}

# Use Graph.dump or Writer.open to save to a file
puts g.dump(:ttl, :standard_prefixes => true)

Turtle::Writer.open('example2.ttl') {|w| w << g}
puts File.read('example2.ttl')




6 Dec 2012                     Ruby SemWeb             6
RDFa Serialization with Haml

   ✤ RDFa writer uses Haml templates write a graph to
     HTML
         ➡   Define your own templates
         ➡   Other examples from Structured Data Linter:
             ➡   http://linter.structured-data.org
             ➡   https://github.com/structured-data/linter/blob/master/lib/rdf/linter/
                 rdfa_template.rb

   ✤ In principle, this can be used to write any XML-
     based format by defining an appropriate template
   ✤ More information in RDFa gem

6 Dec 2012                                 Ruby SemWeb                                   7
Finding Formats
   ✤ Find a format for reading or writing
require 'rdf/rdfa'
require 'rdf/rdfxml'

Writer.for(:ttl)
Writer.for(:content_type => "text/html")
Reader.for('example2.ttl')

# List available formats
RDF::Format.to_a.map(&:to_sym)

# Open a URL and use format detection to find a writer
puts Graph.load('http://greggkellogg.net/foaf').
  dump(:ttl, :base_uri => 'http://greggkellogg.net/foaf',
       :standard_prefixes => true)

f = "http://greggkellogg.net/github-lod/doap.ttl"
Turtle::Reader.open(f) do |reader|
  reader.each {|st| puts st.inspect}
end

6 Dec 2012                         Ruby SemWeb              8
BGP Query support
f = "http://greggkellogg.net/github-lod/doap.ttl"
doap = Graph.load(f)
                                                       ✤ Query with
# using RDF::Query
query = Query.new(
                                                         RDF::Query
  :person => {
      RDF.type => FOAF.Person,
      FOAF.name => :name,
      FOAF.mbox => :email,
  })
query.execute(doap).each do |soln|
  puts "name: #{soln.name}, email: #{soln[:email]}"
end; nil

# using Query::Pattern
query = Query.new do
  pattern [:project, DOAP.developer, :person]
  pattern [:person, FOAF.name, :name]
end
query.execute(doap).each do |soln|
  puts "project: #{soln.project} name: #{soln.name}"
end; nil
6 Dec 2012                         Ruby SemWeb                        9
SPARQL
require 'sparql'                                     ❖ SPARQL gem
f = "./dumps/github-lod.nt"                            executes locally
doap = Graph.load(f)
                                                       for against
query = SPARQL.parse(%q(                               RDF::Queryable
  PREFIX doap: <http://usefulinc.com/ns/doap#>
  PREFIX foaf: <http://xmlns.com/foaf/0.1/>            object.
  SELECT ?repo ?name
                                                     ❖ SPARQL::Client
  WHERE {                                              gem executes
    [ a doap:Project;
      doap:name ?repo;
                                                       against a remote
      doap:developer [ a foaf:Person;                  repository
        foaf:name ?name
        ]
                                                       ➡ Best for querying
    ]                                                    large datasets.
  }
  ORDER BY DESC(?repo)
  LIMIT 20
))
query.execute(doap).each do |soln|
   puts "project: #{soln.repo} name: #{soln.name}"
end; nil




                                        10
RDF Behavior
   ✤ Classes can behave like RDF
         ➡   RDF::Countable – #empty?, #count, #size
         ➡   RDF::Durable
         ➡   RDF::Enumerable – must implement #each
             –   #statements, #each, #triples, #quads, ...
         ➡   RDF::Writable – must implement #(insert/delete/each)_statement
             –   #load, #insert, #<<, #update, #delete
         ➡   RDF::Queryable – must implement #each
             ➡   should implement #query_pattern & #query_execute
             –   #query, #first, #first_(subject,predicate,object)
         –   RDF::TypeCheck – raises TypeError on illegal comparison

6 Dec 2012                                 Ruby SemWeb                        11
ActiveRecord with RDF
   ✤ Import #RDF::Enumerable and implement #each
require 'github-api-client'
class GitHub::User
  include RDF::Enumerable
  def each
    u = RDF::URI("http://github.com/#{login}")
    yield RDF::Statement.new(u, RDF::FOAF.name, name)
    yield RDF::Statement.new(u, RDF::mbox, RDF::URI("mailto:#{email}")) unless email.nil?
  end
end

u = GitHub::User.get('gkellogg')
puts u.dump(:ttl, :standard_prefixes => true)




6 Dec 2012                            Ruby SemWeb                               12
Other Resources
   ✤ Spira
         ➡   Get Ruby classes from RDF datastores

   ✤ Distiller
         ➡   Transform between RDF formats, including RDFa generation
         ➡   http://rdf.greggkellogg.net

   ✤ Documentation
         ➡   Comprehensive documentation of Ruby LinkedData related gems available at
             http://rdf.greggkellogg.net/yard/index.html

   ✤ GitHub LOD Demo
         ➡   Examples used in this presentation, along with a demo Sinatra application
             illustrating Ruby RDF usage is available:
             ➡   GitHub project: http://github.com/gkellogg/github-lod (Public Domain)
             ➡   Running demo: http://greggkellogg.net/github-lod
6 Dec 2012                                 Ruby SemWeb                                   13

Más contenido relacionado

La actualidad más candente

Bigdive 2014 - RDF, principles and case studies
Bigdive 2014 - RDF, principles and case studiesBigdive 2014 - RDF, principles and case studies
Bigdive 2014 - RDF, principles and case studies
Diego Valerio Camarda
 

La actualidad más candente (20)

An Introduction to SPARQL
An Introduction to SPARQLAn Introduction to SPARQL
An Introduction to SPARQL
 
XSPARQL Tutorial
XSPARQL TutorialXSPARQL Tutorial
XSPARQL Tutorial
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
Bigdive 2014 - RDF, principles and case studies
Bigdive 2014 - RDF, principles and case studiesBigdive 2014 - RDF, principles and case studies
Bigdive 2014 - RDF, principles and case studies
 
#sod14 - ok, è un endpoint SPARQL non facciamoci prendere dal panico
#sod14 - ok, è un endpoint SPARQL non facciamoci prendere dal panico#sod14 - ok, è un endpoint SPARQL non facciamoci prendere dal panico
#sod14 - ok, è un endpoint SPARQL non facciamoci prendere dal panico
 
3 apache-avro
3 apache-avro3 apache-avro
3 apache-avro
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQL
 
RDF Stream Processing Models (SR4LD2013)
RDF Stream Processing Models (SR4LD2013)RDF Stream Processing Models (SR4LD2013)
RDF Stream Processing Models (SR4LD2013)
 
Code as Data workshop: Using source{d} Engine to extract insights from git re...
Code as Data workshop: Using source{d} Engine to extract insights from git re...Code as Data workshop: Using source{d} Engine to extract insights from git re...
Code as Data workshop: Using source{d} Engine to extract insights from git re...
 
SUMMER SCHOOL LEX 2014 - RDF + SPARQL querying the web of (lex)data
SUMMER SCHOOL LEX 2014 - RDF + SPARQL querying the web of (lex)dataSUMMER SCHOOL LEX 2014 - RDF + SPARQL querying the web of (lex)data
SUMMER SCHOOL LEX 2014 - RDF + SPARQL querying the web of (lex)data
 
Querying the Web of Data with XSPARQL 1.1
Querying the Web of Data with XSPARQL 1.1Querying the Web of Data with XSPARQL 1.1
Querying the Web of Data with XSPARQL 1.1
 
2007 03 12 Swecr 2
2007 03 12 Swecr 22007 03 12 Swecr 2
2007 03 12 Swecr 2
 
ApacheCon09: Avro
ApacheCon09: AvroApacheCon09: Avro
ApacheCon09: Avro
 
Avro intro
Avro introAvro intro
Avro intro
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
 
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
 
3 avro hug-2010-07-21
3 avro hug-2010-07-213 avro hug-2010-07-21
3 avro hug-2010-07-21
 

Destacado

HTML5 and microformats for pragmatists
HTML5 and microformats for pragmatistsHTML5 and microformats for pragmatists
HTML5 and microformats for pragmatists
Wojtek Zając
 
Plan Estratégico 2012 - 2014
Plan Estratégico 2012 - 2014Plan Estratégico 2012 - 2014
Plan Estratégico 2012 - 2014
laspalmasgces
 
JSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsJSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web Apps
Gregg Kellogg
 
M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...
M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...
M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...
Torres Salinas
 
Plan de Emergencias Municipal
Plan de Emergencias Municipal Plan de Emergencias Municipal
Plan de Emergencias Municipal
laspalmasgces
 

Destacado (20)

20130628 Taller H2020 Lleida EIP agricultura sostenible: AMontero
20130628 Taller H2020 Lleida EIP agricultura sostenible: AMontero20130628 Taller H2020 Lleida EIP agricultura sostenible: AMontero
20130628 Taller H2020 Lleida EIP agricultura sostenible: AMontero
 
#MoocVT: Introducción a la vigilancia tecnológica para emprender en red
#MoocVT: Introducción a la vigilancia tecnológica para emprender en red#MoocVT: Introducción a la vigilancia tecnológica para emprender en red
#MoocVT: Introducción a la vigilancia tecnológica para emprender en red
 
Presentación institucional del OVTT (Febrero, 2014)
Presentación institucional del OVTT (Febrero, 2014)Presentación institucional del OVTT (Febrero, 2014)
Presentación institucional del OVTT (Febrero, 2014)
 
Accion contra el Hambre - The Flying Challenge
Accion contra el Hambre - The Flying ChallengeAccion contra el Hambre - The Flying Challenge
Accion contra el Hambre - The Flying Challenge
 
LPA_GC: Smart City
LPA_GC: Smart CityLPA_GC: Smart City
LPA_GC: Smart City
 
III Congreso Internacional RedUE-ALCUE: redes de valor para la vigilancia tec...
III Congreso Internacional RedUE-ALCUE: redes de valor para la vigilancia tec...III Congreso Internacional RedUE-ALCUE: redes de valor para la vigilancia tec...
III Congreso Internacional RedUE-ALCUE: redes de valor para la vigilancia tec...
 
HTML5 and microformats for pragmatists
HTML5 and microformats for pragmatistsHTML5 and microformats for pragmatists
HTML5 and microformats for pragmatists
 
Introduction to social media for researchers
Introduction to social media for researchersIntroduction to social media for researchers
Introduction to social media for researchers
 
Conferencia virtual del OVTT para Colombia (COMPLETO)
Conferencia virtual del OVTT para Colombia (COMPLETO)Conferencia virtual del OVTT para Colombia (COMPLETO)
Conferencia virtual del OVTT para Colombia (COMPLETO)
 
Plan Estratégico 2012 - 2014
Plan Estratégico 2012 - 2014Plan Estratégico 2012 - 2014
Plan Estratégico 2012 - 2014
 
Presentation
PresentationPresentation
Presentation
 
I Convención Internacional de Ciencia y Tecnología
I Convención Internacional de Ciencia y TecnologíaI Convención Internacional de Ciencia y Tecnología
I Convención Internacional de Ciencia y Tecnología
 
JSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsJSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web Apps
 
M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...
M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...
M2.Curso Apoyo Investigación Bibliotecas. Bibliotecarios integrados (embedded...
 
Twitterology - The Science of Twitter
Twitterology - The Science of TwitterTwitterology - The Science of Twitter
Twitterology - The Science of Twitter
 
Human Mobility (with Mobile Devices)
Human Mobility (with Mobile Devices)Human Mobility (with Mobile Devices)
Human Mobility (with Mobile Devices)
 
OVTT: Internet como espacio de relación y transformación para innovar en el s...
OVTT: Internet como espacio de relación y transformación para innovar en el s...OVTT: Internet como espacio de relación y transformación para innovar en el s...
OVTT: Internet como espacio de relación y transformación para innovar en el s...
 
Innovación abierta y transferencia de tecnología desde la Universidad de Alic...
Innovación abierta y transferencia de tecnología desde la Universidad de Alic...Innovación abierta y transferencia de tecnología desde la Universidad de Alic...
Innovación abierta y transferencia de tecnología desde la Universidad de Alic...
 
OVTT: Vigilancia tecnológica para innovar en red
OVTT: Vigilancia tecnológica para innovar en redOVTT: Vigilancia tecnológica para innovar en red
OVTT: Vigilancia tecnológica para innovar en red
 
Plan de Emergencias Municipal
Plan de Emergencias Municipal Plan de Emergencias Municipal
Plan de Emergencias Municipal
 

Similar a Ruby semweb 2011-12-06

Slides semantic web and Drupal 7 NYCCamp 2012
Slides semantic web and Drupal 7 NYCCamp 2012Slides semantic web and Drupal 7 NYCCamp 2012
Slides semantic web and Drupal 7 NYCCamp 2012
scorlosquet
 
Publishing Linked Data 3/5 Semtech2011
Publishing Linked Data 3/5 Semtech2011Publishing Linked Data 3/5 Semtech2011
Publishing Linked Data 3/5 Semtech2011
Juan Sequeda
 
Ks2008 Semanticweb In Action
Ks2008 Semanticweb In ActionKs2008 Semanticweb In Action
Ks2008 Semanticweb In Action
Rinke Hoekstra
 

Similar a Ruby semweb 2011-12-06 (20)

RejectKaigi2010 - RDF.rb
RejectKaigi2010 - RDF.rbRejectKaigi2010 - RDF.rb
RejectKaigi2010 - RDF.rb
 
Graph databases & data integration v2
Graph databases & data integration v2Graph databases & data integration v2
Graph databases & data integration v2
 
Slides semantic web and Drupal 7 NYCCamp 2012
Slides semantic web and Drupal 7 NYCCamp 2012Slides semantic web and Drupal 7 NYCCamp 2012
Slides semantic web and Drupal 7 NYCCamp 2012
 
Apache Jena Elephas and Friends
Apache Jena Elephas and FriendsApache Jena Elephas and Friends
Apache Jena Elephas and Friends
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
A Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic WebA Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic Web
 
Publishing Linked Data 3/5 Semtech2011
Publishing Linked Data 3/5 Semtech2011Publishing Linked Data 3/5 Semtech2011
Publishing Linked Data 3/5 Semtech2011
 
Semantic Web introduction
Semantic Web introductionSemantic Web introduction
Semantic Web introduction
 
RDFa: introduction, comparison with microdata and microformats and how to use it
RDFa: introduction, comparison with microdata and microformats and how to use itRDFa: introduction, comparison with microdata and microformats and how to use it
RDFa: introduction, comparison with microdata and microformats and how to use it
 
Taming NoSQL with Spring Data
Taming NoSQL with Spring DataTaming NoSQL with Spring Data
Taming NoSQL with Spring Data
 
Quadrupling your elephants - RDF and the Hadoop ecosystem
Quadrupling your elephants - RDF and the Hadoop ecosystemQuadrupling your elephants - RDF and the Hadoop ecosystem
Quadrupling your elephants - RDF and the Hadoop ecosystem
 
Bringing the Semantic Web closer to reality: PostgreSQL as RDF Graph Database
Bringing the Semantic Web closer to reality: PostgreSQL as RDF Graph DatabaseBringing the Semantic Web closer to reality: PostgreSQL as RDF Graph Database
Bringing the Semantic Web closer to reality: PostgreSQL as RDF Graph Database
 
Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)
 
The Semantic Web and Drupal 7 - Loja 2013
The Semantic Web and Drupal 7 - Loja 2013The Semantic Web and Drupal 7 - Loja 2013
The Semantic Web and Drupal 7 - Loja 2013
 
An Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of DataAn Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of Data
 
Demo 0.9.4
Demo 0.9.4Demo 0.9.4
Demo 0.9.4
 
Linked Data on Rails
Linked Data on RailsLinked Data on Rails
Linked Data on Rails
 
Ks2008 Semanticweb In Action
Ks2008 Semanticweb In ActionKs2008 Semanticweb In Action
Ks2008 Semanticweb In Action
 
RDFa Introductory Course Session 2/4 How RDFa
RDFa Introductory Course Session 2/4 How RDFaRDFa Introductory Course Session 2/4 How RDFa
RDFa Introductory Course Session 2/4 How RDFa
 
How RDFa works
How RDFa worksHow RDFa works
How RDFa works
 

Más de Gregg Kellogg (6)

JSON-LD update DC 2017
JSON-LD update DC 2017JSON-LD update DC 2017
JSON-LD update DC 2017
 
JSON-LD Update
JSON-LD UpdateJSON-LD Update
JSON-LD Update
 
Tabular Data on the Web
Tabular Data on the WebTabular Data on the Web
Tabular Data on the Web
 
JSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social WebJSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social Web
 
JSON-LD and MongoDB
JSON-LD and MongoDBJSON-LD and MongoDB
JSON-LD and MongoDB
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked Data
 

Último

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Ruby semweb 2011-12-06

  • 1. Linked Open Data for Rubyists What the Semantic Web brings to Ruby Gregg Kellogg gregg@greggkellogg.net Twitter: @gkellogg G+: greggkellogg
  • 2. Why RDF for Ruby? ✤ Major creative force in Web 2.0 ✤ Rich eco-system (Gems/Rails/…) ✤ Fair support for XML (Nokogiri, anyway) ✤ Great environment for prototyping and getting stuff done. ✤ RDF is relatively virgin territory in Ruby 6 Dec 2012 Ruby SemWeb 2
  • 3. Ruby RDF ❖ RDF.rb/linkeddata ❖ Storage ❖ Readers/Writers ➡ Cassandra ➡ RDF/XML ➡ SQL(RDF::DO) ➡ N3/Turtle/NTriples ➡ MongoDB ➡ NQuads/TriX ➡ Redstore ➡ RDFa/Microdata ➡ Sesame ➡ JSON-LD/RDF-JSON ➡ AlegroGraph ➡ Raptor bridge ➡ Talis ➡ 4store ❖ Query ➡ SPARQL/SSE ➡ SPARQL::Client 6 Dec 2012 Ruby SemWeb 3
  • 4. Core Classes ❖ RDF::Term ❖ Serializations ➡ RDF::Literal ➡ RDF::Format ➡ XSD subtypes ➡ RDF::Reader ➡ RDF::Resource ➡ RDF::Writer ➡ RDF::Node ❖ Storage ➡ RDF::URI ➡ RDF::Repository ➡ RDF::List ❖ Query ➡ RDF::Graph ➡ RDF::Query ❖ RDF::Statement ➡ RDF::Query::Pattern ❖ RDF::Vocabulary ➡ RDF::Query::Solution ➡ With definitions for common ➡ RDF::Query::Variable vocabularies 6 Dec 2012 Ruby SemWeb 4
  • 5. Simple Graph Manipulation require 'rdf' include RDF g = Graph.new g << Statement.new( RDF::URI.new("https://github.com/gkellogg/rdf"), RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), RDF::URI.new("http://usefulinc.com/ns/doap#GitRepository")) # Using common vocabularies proj = Node.new g << Statement.new(proj, RDF.type, DOAP.Project) g << Statement.new(proj, DOAP.repository, RDF::URI.new("https://github.com/gkellogg/rdf")) puts g.dump(:ntriples) 6 Dec 2012 Ruby SemWeb 5
  • 6. Serializing with Writers ✤ Graphs can be serialized with available Writers require 'rdf/ntriples' require 'rdf/turtle' puts NTriples::Writer.buffer {|writer| writer << g} # Also, you can include other formats Turtle::Writer.buffer {|writer| writer << g} # Use Graph.dump or Writer.open to save to a file puts g.dump(:ttl, :standard_prefixes => true) Turtle::Writer.open('example2.ttl') {|w| w << g} puts File.read('example2.ttl') 6 Dec 2012 Ruby SemWeb 6
  • 7. RDFa Serialization with Haml ✤ RDFa writer uses Haml templates write a graph to HTML ➡ Define your own templates ➡ Other examples from Structured Data Linter: ➡ http://linter.structured-data.org ➡ https://github.com/structured-data/linter/blob/master/lib/rdf/linter/ rdfa_template.rb ✤ In principle, this can be used to write any XML- based format by defining an appropriate template ✤ More information in RDFa gem 6 Dec 2012 Ruby SemWeb 7
  • 8. Finding Formats ✤ Find a format for reading or writing require 'rdf/rdfa' require 'rdf/rdfxml' Writer.for(:ttl) Writer.for(:content_type => "text/html") Reader.for('example2.ttl') # List available formats RDF::Format.to_a.map(&:to_sym) # Open a URL and use format detection to find a writer puts Graph.load('http://greggkellogg.net/foaf'). dump(:ttl, :base_uri => 'http://greggkellogg.net/foaf', :standard_prefixes => true) f = "http://greggkellogg.net/github-lod/doap.ttl" Turtle::Reader.open(f) do |reader| reader.each {|st| puts st.inspect} end 6 Dec 2012 Ruby SemWeb 8
  • 9. BGP Query support f = "http://greggkellogg.net/github-lod/doap.ttl" doap = Graph.load(f) ✤ Query with # using RDF::Query query = Query.new( RDF::Query :person => { RDF.type => FOAF.Person, FOAF.name => :name, FOAF.mbox => :email, }) query.execute(doap).each do |soln| puts "name: #{soln.name}, email: #{soln[:email]}" end; nil # using Query::Pattern query = Query.new do pattern [:project, DOAP.developer, :person] pattern [:person, FOAF.name, :name] end query.execute(doap).each do |soln| puts "project: #{soln.project} name: #{soln.name}" end; nil 6 Dec 2012 Ruby SemWeb 9
  • 10. SPARQL require 'sparql' ❖ SPARQL gem f = "./dumps/github-lod.nt" executes locally doap = Graph.load(f) for against query = SPARQL.parse(%q( RDF::Queryable PREFIX doap: <http://usefulinc.com/ns/doap#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> object. SELECT ?repo ?name ❖ SPARQL::Client WHERE { gem executes [ a doap:Project; doap:name ?repo; against a remote doap:developer [ a foaf:Person; repository foaf:name ?name ] ➡ Best for querying ] large datasets. } ORDER BY DESC(?repo) LIMIT 20 )) query.execute(doap).each do |soln| puts "project: #{soln.repo} name: #{soln.name}" end; nil 10
  • 11. RDF Behavior ✤ Classes can behave like RDF ➡ RDF::Countable – #empty?, #count, #size ➡ RDF::Durable ➡ RDF::Enumerable – must implement #each – #statements, #each, #triples, #quads, ... ➡ RDF::Writable – must implement #(insert/delete/each)_statement – #load, #insert, #<<, #update, #delete ➡ RDF::Queryable – must implement #each ➡ should implement #query_pattern & #query_execute – #query, #first, #first_(subject,predicate,object) – RDF::TypeCheck – raises TypeError on illegal comparison 6 Dec 2012 Ruby SemWeb 11
  • 12. ActiveRecord with RDF ✤ Import #RDF::Enumerable and implement #each require 'github-api-client' class GitHub::User include RDF::Enumerable def each u = RDF::URI("http://github.com/#{login}") yield RDF::Statement.new(u, RDF::FOAF.name, name) yield RDF::Statement.new(u, RDF::mbox, RDF::URI("mailto:#{email}")) unless email.nil? end end u = GitHub::User.get('gkellogg') puts u.dump(:ttl, :standard_prefixes => true) 6 Dec 2012 Ruby SemWeb 12
  • 13. Other Resources ✤ Spira ➡ Get Ruby classes from RDF datastores ✤ Distiller ➡ Transform between RDF formats, including RDFa generation ➡ http://rdf.greggkellogg.net ✤ Documentation ➡ Comprehensive documentation of Ruby LinkedData related gems available at http://rdf.greggkellogg.net/yard/index.html ✤ GitHub LOD Demo ➡ Examples used in this presentation, along with a demo Sinatra application illustrating Ruby RDF usage is available: ➡ GitHub project: http://github.com/gkellogg/github-lod (Public Domain) ➡ Running demo: http://greggkellogg.net/github-lod 6 Dec 2012 Ruby SemWeb 13

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n