SlideShare a Scribd company logo
The	
  Seman)c	
  Web	
  
RDF,	
  SPARQL	
  and	
  so0ware	
  
APIs	
  
4IZ440	
  Knowledge	
  Representa4on	
  and	
  Reasoning	
  on	
  the	
  WWW	
  
Josef	
  Petrák	
  |	
  me@jspetrak.name	
  
	
  
Worth	
  a	
  note	
  
§  Open	
  Data	
  iniDave	
  around	
  world	
  and	
  Europe	
  open	
  staDsDcal	
  and	
  
    government	
  data,	
  usually	
  in	
  RDF	
  format.	
  
§  It	
  has	
  several	
  success	
  stories	
  
    §  hLp://headtoweb.posterous.com/open-­‐data-­‐success-­‐stories	
  
§  Google	
  is	
  integraDng	
  RDF	
  encoded	
  as	
  RDFa	
  in	
  pages	
  into	
  its	
  search	
  
    results.	
  

§  UEP	
  is	
  not	
  behind	
  –	
  DIKE	
  research	
  group	
  KEG	
  started	
  Czech–Slovak	
  
    semanDc	
  iniDaDve	
  called	
  SemanDcs	
  
§  And	
  we	
  have	
  a	
  RDF-­‐based	
  website	
  deployed,	
  see	
  
    hLp://keg.vse.cz/	
  
Outline	
  
§  RDF	
  representaDon	
  formats	
  
§  Data	
  handling	
  approaches	
  
§  So0ware	
  APIs	
  overview	
  
§  Approaches	
  in	
  examples	
  
§  MoDvaDon	
  example:	
  web	
  applicaDon	
  
RDF	
  representaDon	
  
Syntaxes	
  
§  RDF	
  has	
  several	
  syntaxes.	
  
§  A	
  “graph”	
  is	
  the	
  reference	
  syntax.	
  
§  The	
  W3C	
  endorsed	
  file	
  format	
  is	
  RDF/XML	
  
§  Other	
  file	
  formats:	
  
   §  N-­‐Triples	
  
   §  N3	
  
   §  RDF/JSON	
  
   §  RDFa	
  
RDF	
  graph 	
  	
  
                            rdf:type	
                            gd:Person	
  



                            gd:name	
                          John	
  Example	
  


          gd:affiliaDon	
  
                                           Sample	
  Corp.	
  Inc.	
  



PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>	
PREFIX gd: <http://rdf.data-vocabulary.org/#>
RDF/XML	
  
<rdf:RDF	
  
	
  	
  xmlns:rdf=“http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”	
  
	
  	
  xmlns:gd=“http://rdf.data-­‐vocabulary.org/#”>	
  
	
  	
  <rdf:Resource>	
  
	
  	
  	
  	
  <rdf:type	
  rdf:resource=“http://rdf.data-­‐vocabulary.org/#Person”/>	
  
	
  	
  	
  	
  <gd:name>John	
  Example</gd:name>	
  
	
  	
  	
  	
  <gd:affiliation>Sample	
  Corp.	
  Inc.</gd:affiliation>	
  
	
  	
  </rdf:Resource>	
  
</rdf:RDF>	
  
RDF/XML	
  (shortened)	
  
<rdf:RDF	
  
	
  	
  xmlns:rdf=“http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”	
  
	
  	
  xmlns:gd=“http://rdf.data-­‐vocabulary.org/#”>	
  
	
  	
  <gd:Person>	
  
	
  	
  	
  	
  <gd:name>John	
  Example</gd:name>	
  
	
  	
  	
  	
  <gd:affiliation>Sample	
  Corp.	
  Inc.</gd:affiliation>	
  
	
  	
  </gd:Person>	
  
</rdf:RDF>	
  
N3	
  NotaDon	
  
@prefix	
  gd:	
  <http://rdf.data-­‐vocabulary.org/#>	
  .	
  
	
  
[]	
  a	
  gd:Person;	
  
	
  	
  gd:name	
  “John	
  Example”;	
  
	
  	
  gd:affiliation	
  “Sample	
  Corp.	
  Inc.”	
  .	
  
N–Triples	
  
_:a	
  <http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#type>	
  	
  
           	
  <http://rdf.data-­‐vocabulary.org/#Person>	
  .	
  
_:a	
  <http://rdf.data-­‐vocabulary.org/#name>	
  	
  
           	
  “John	
  Example”	
  .	
  
_:a	
  <http://rdf.data-­‐vocabulary.org/#affiliation>	
  	
  
           	
  “Sample	
  Corp.	
  Inc.”	
  .	
  
	
§  Primarily	
  used	
  to	
  defined	
  RDF	
  test	
  cases	
  
§  Subset	
  of	
  N3	
  NotaDon	
  
RDF/JSON	
  
{	
  
	
  	
  “_:a“	
  :	
  {	
  
	
  	
  	
  	
  “http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”	
  :	
  [	
  
	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  “value“	
  :	
  “http://rdf.data-­‐vocabulary.org/#Person”,	
  “type“	
  :	
  “uri“	
  
	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  ],	
  
	
  	
  	
  	
  “http://rdf.data-­‐vocabulary.org/#name”	
  :	
  [	
  
	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  “value“	
  :	
  “John	
  Example“,	
  “type“	
  :	
  “literal“	
  
	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  ],	
  
	
  	
  	
  	
  “http://rdf.data-­‐vocabulary.org/#affiliation”	
  :	
  [	
  
	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  “value“	
  :	
  “Sample	
  Corp.	
  Inc.“,	
  “type“	
  :	
  “literal“	
  
	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  ]	
  
	
  	
  }	
  
}	
  
RDFa	
  
<html	
  
	
  	
  xmlns=“http://www.w3.org/1999/xhtml”	
  
	
  	
  xmlns:rdf=“http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”	
  
	
  	
  xmlns:gd=“http://rdf.data-­‐vocabulary.org/#”>	
  
	
  
<p	
  typeof=“gd:Person”>	
  
	
  	
  <em	
  property=“gd:name”>John	
  Example</em>	
  is	
  working	
  	
  
	
  	
  at	
  <em	
  property=“gd:affiliation”>Sample	
  Corp.	
  Inc.</em>.	
  
</p>	
  
	
  
</html>	
  
Resources	
  about	
  RDF	
  formats	
  
§  RDF/XML	
  
    §  hLp://www.w3.org/TR/rdf-­‐syntax-­‐grammar/	
  
§  N3	
  NotaDon	
  
    §  hLp://www.w3.org/DesignIssues/NotaDon3	
  
    §  hLp://www.w3.org/2000/10/swap/Primer	
  
§  N–Triples	
  
    §  hLp://www.w3.org/TR/rdf-­‐testcases/#ntriples	
  
§  RDF/JSON	
  
    §  hLp://n2.talis.com/wiki/RDF_JSON_SpecificaDon	
  
§  RDFa	
  
    §  hLp://www.w3.org/TR/rdfa-­‐syntax/	
  
Task	
  #1	
  
1.  Use	
  Google	
  Data	
  Vocabulary	
  
   §  hLp://www.data-­‐vocabulary.org/Person/	
  
2.  Created	
  a	
  NotaDon3	
  file	
  with	
  demo	
  data	
  about	
  people	
  
Data	
  handling	
  
RDF	
  models	
  
§  Statement–centric	
  
   §  Working	
  with	
  triples	
  of	
  ?subject	
  ?predicate	
  ?object	
  
§  Resource–centric	
  
   §  Working	
  with	
  resources	
  having	
  properDes	
  and	
  their	
  values	
  
§  Ontology–centric	
  
   §  Working	
  with	
  classes,	
  properDes,	
  and	
  individuals	
  as	
  defined	
  in	
  selected	
  
       vocabulary/schema/ontology	
  
§  Named	
  graph	
  
   §  Triples	
  belongs	
  to	
  a	
  graph	
  with	
  URI	
  name	
  
   §  Working	
  with	
  quads	
  of	
  ?graph	
  ?subject	
  ?predicate	
  ?object	
  
So0ware	
  APIs	
  
Java	
  
§  Jena	
  
    §  hLp://openjena.org/	
  
    §  hLp://sourceforge.net/projects/jena/	
  
§  Sesame	
  
    §  hLp://www.openrdf.org/	
  
§  Shellac	
  RDFa	
  Parser	
  
    §  hLps://github.com/shellac/java-­‐rdfa	
  
PHP	
  
§  RDF	
  API	
  for	
  PHP	
  (RAP)	
  
    §  hLp://www4.wiwiss.fu-­‐berlin.de/bizer/rdfapi/	
  
    §  hLp://sourceforge.net/projects/rdfapi-­‐php/	
  
§  ARC2	
  
    §  hLp://arc.semsol.org/	
  
Ruby	
  
§  RDF.rb	
  
    §  hLp://rdf.rubyforge.org/	
  
    §  hLps://github.com/bendiken/rdf	
  
    §  Plus	
  various	
  modules	
  
Code	
  Examples	
  
File-­‐read	
  
§  Task:	
  Read	
  RDF	
  data	
  from	
  a	
  NotaDon3	
  file	
  format	
  into	
  memory	
  
    model.	
  
Read	
  N3	
  (Jena)	
  
InputStream	
  is	
  =	
  	
  
	
  	
  FileManager.get().open("samples/people.n3");	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  
Model	
  model	
  =	
  ModelFactory.createDefaultModel();	
  
RDFReader	
  r	
  =	
  model.getReader("N3");	
  
r.read(model,	
  is,	
  null);	
  
is.close();	
  
Read	
  N3	
  (RDF.rb)	
  
repository	
  =	
  RDF::Repository.new	
  
	
  
RDF::N3::Reader.open(‘samples/people.n3’)	
  {	
  |reader|	
  
	
  	
  repository	
  <<	
  	
  reader	
  
}	
  
Read	
  N3	
  (ARC2)	
  
$parser	
  =	
  ARC2::getRDFParser();	
  
$parser-­‐>parse(‘samples/people.n3');	
  
     	
  	
  
$triples	
  =	
  $parser-­‐>getTriples();	
  
Read	
  N3	
  (RAP)	
  
$model	
  =	
  ModelFactory::getDefaultModel();	
  
$model-­‐>load('samples/people.n3');	
  

§  This	
  code	
  won’t	
  run,	
  because	
  there	
  is	
  N3Reader	
  bug.	
  
§  Works	
  also	
  for	
  RDF/XML	
  and	
  N–Triples	
  formats.	
  
Traverse	
  triples	
  
§  Task:	
  Take	
  a	
  memory	
  model	
  and	
  list	
  all	
  or	
  parDcular	
  RDF	
  triples.	
  
Traverse	
  triples	
  (Jena)	
  
Model	
  model	
  =	
  ModelFactory.createDefaultModel();	
  
//	
  Load	
  data	
  into	
  model	
  
	
  	
  	
  	
  	
  	
  	
  
StmtIterator	
  i	
  =	
  model.listStatements();	
  
while	
  (i.hasNext())	
  {	
  
	
  	
  Statement	
  stmt	
  =	
  i.nextStatement();	
  
	
  	
  Resource	
  subject	
  =	
  stmt.getSubject();	
  
	
  	
  Property	
  predicate	
  =	
  stmt.getPredicate();	
  
	
  	
  RDFNode	
  object	
  =	
  stmt.getObject();	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  //	
  Printing	
  out	
  
}	
  
Query	
  Model	
  (Jena)	
  
Resource	
  rPerson	
  =	
  model.getResource("http://rdf.data-­‐
vocabulary.org/#Person");	
  
Property	
  rName	
  =	
  model.getProperty("http://rdf.data-­‐vocabulary.org/
#name");	
  
	
  
StmtIterator	
  si	
  =	
  model.listStatements(null,	
  RDF.type,	
  rPerson);	
  
while	
  (si.hasNext())	
  {	
  
	
  	
  Resource	
  r	
  =	
  si.nextStatement().getSubject();	
  
	
  	
  StmtIterator	
  sii	
  =	
  model.listStatements(r,	
  rName,	
  (RDFNode)null);	
  
	
  	
  if	
  (sii.hasNext())	
  {	
  
	
  	
  	
  	
  System.out.println(sii.nextStatement().getObject().toString());	
  
	
  	
  }	
  
}	
  
Traverse	
  triples	
  (RDF.rb)	
  
repository	
  =	
  RDF::Repository.new	
  
#	
  Load	
  data	
  
	
  
repository.each_statement	
  {	
  |statement|	
  
	
  	
  puts	
  statement	
  
}	
  
Query	
  model	
  (RDF.rb)	
  
GD	
  =	
  RDF::Vocabulary.new('http://rdf.data-­‐vocabulary.org/#')	
  
	
  
repository	
  =	
  RDF::Repository.new	
  
#	
  Load	
  data	
  
	
  
query	
  =	
  RDF::Query.new({	
  
	
  	
  :person	
  =>	
  {	
  
	
  	
  	
  	
  RDF.type	
  =>	
  GD.Person,	
  GD.name	
  =>	
  :name	
  
	
  	
  }	
  
})	
  
	
  
query.execute(graph).each	
  do	
  |person|	
  
	
  	
  puts	
  "name=#{person.name}"	
  
end	
  
Query	
  SPARQL	
  Endpoint	
  
§  Task:	
  Query	
  a	
  SPARQL	
  endpoint	
  and	
  write	
  out	
  the	
  data.	
  E.g.	
  from	
  
    DBPedia,	
  write	
  one	
  random	
  blackboard	
  gag	
  wriLen	
  by	
  Bart	
  
    Simpson.	
  
Query	
  SPARQL	
  Endpoint	
  (Jena)	
  
String	
  qa	
  =	
  "PREFIX	
  skos:	
  <http://www.w3.org/2004/02/skos/core#>"	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "PREFIX	
  dbpprop:	
  <http://dbpedia.org/property/>"	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "PREFIX	
  dcterms:	
  <http://purl.org/dc/terms/>"	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "PREFIX	
  rdfs:	
  <http://www.w3.org/2000/01/rdf-­‐schema#>"	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "SELECT	
  ?gag	
  WHERE	
  {	
  "	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "?series	
  skos:broader	
  <http://dbpedia.org/resource/
Category:The_Simpsons_episodes>	
  ."	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "	
  	
  ?episode	
  dcterms:subject	
  ?series	
  ."	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "	
  	
  ?episode	
  dbpprop:blackboard	
  ?gag	
  ."	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "}"	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  +	
  "LIMIT	
  1000";	
  
Query	
  q	
  =	
  QueryFactory.create(qa);	
  	
  	
  	
  	
  	
  	
  	
  	
  
QueryExecution	
  qe	
  =	
  	
  
	
  	
  QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql",	
  q);	
  
ResultSet	
  rs	
  =	
  qe.execSelect();	
  
ResultSetFormatter.out(System.out,	
  rs,	
  q);	
  
qe.close();	
  
Query	
  SPARQL	
  Endpoint	
  (RDF.rb)	
  
sparql	
  =	
  	
  
	
  	
  SPARQL::Client.new("http://dbpedia.org/sparql")	
  
	
  
result	
  =	
  sparql.query("SELECT	
  ?gag	
  WHERE	
  {	
  	
  
	
  	
  ?series	
  skos:broader	
  <http://dbpedia.org/resource/
Category:The_Simpsons_episodes>	
  .	
  
	
  	
  ?episode	
  dcterms:subject	
  ?series	
  .	
  
	
  	
  ?episode	
  dbpprop:blackboard	
  ?gag	
  .	
  
}	
  
LIMIT	
  1000")	
  
	
  
puts	
  result[rand(result.length)][:gag]	
  
Query	
  SPARQL	
  Endpoint	
  (RAP)	
  
$client	
  =	
  	
  
	
  	
  ModelFactory::getSparqlClient("http://www.exampleSparqlService.net:2020/
example");	
  
	
  
$query	
  =	
  new	
  ClientQuery();	
  
$query-­‐>query(‘PREFIX	
  skos:	
  <http://www.w3.org/2004/02/skos/core#>	
  
               	
  PREFIX	
  dbpprop:	
  <http://dbpedia.org/property/>	
  
               	
  PREFIX	
  dcterms:	
  <http://purl.org/dc/terms/>	
  
               	
  PREFIX	
  rdfs:	
  <http://www.w3.org/2000/01/rdf-­‐schema#>	
  
               	
  SELECT	
  ?gag	
  WHERE	
  {	
  
               	
  	
  	
  ?series	
  skos:broader	
  <http://dbpedia.org/resource/
Category:The_Simpsons_episodes>	
  .	
  
               	
  	
  	
  ?episode	
  dcterms:subject	
  ?series	
  .	
  
               	
  	
  	
  ?episode	
  dbpprop:blackboard	
  ?gag	
  .	
  
               	
  }	
  LIMIT	
  1000’);	
  
$result	
  =	
  $client-­‐>query($query);	
  
	
  
foreach($result	
  as	
  $line){	
  echo($line['?gag']-­‐>toString());	
  }	
  
Query	
  SPARQL	
  Endpoint	
  (ARC2)	
  
$store	
  =	
  	
  
	
  	
  ARC2::getRemoteStore(	
  
	
  	
  	
  	
  array('remote_store_endpoint'	
  =>	
  'http://dbpedia.org/sparql'));	
  
	
  
$q	
  =	
  ‘PREFIX	
  skos:	
  <http://www.w3.org/2004/02/skos/core#>	
  
                    	
  PREFIX	
  dbpprop:	
  <http://dbpedia.org/property/>	
  
                    	
  PREFIX	
  dcterms:	
  <http://purl.org/dc/terms/>	
  
                    	
  PREFIX	
  rdfs:	
  <http://www.w3.org/2000/01/rdf-­‐schema#>	
  
                    	
  SELECT	
  ?gag	
  WHERE	
  {	
  
                    	
  	
  	
  ?series	
  skos:broader	
  <http://dbpedia.org/resource/
Category:The_Simpsons_episodes>	
  .	
  
                    	
  	
  	
  ?episode	
  dcterms:subject	
  ?series	
  .	
  
                    	
  	
  	
  ?episode	
  dbpprop:blackboard	
  ?gag	
  .	
  
                    	
  }	
  LIMIT	
  1000’;	
  
	
  
$rows	
  =	
  $store-­‐>query($q,	
  'rows');	
  
	
  
Task	
  #2	
  
1.  Select	
  one	
  of	
  frameworks	
  (preferably	
  Jena)	
  
2.  Load	
  data	
  from	
  your	
  NotaDon3	
  file	
  
3.  Write	
  out	
  names	
  and	
  work	
  Dtles	
  of	
  people	
  
MoDvaDon	
  Example	
  
Knowledge	
  Engineering	
  Group	
  
Website	
  
§  hLp://keg.vse.cz/	
  
§  RDF	
  outside	
  
    §  Data	
  dumps	
  in	
  RDF/XML	
  
    §  Web	
  pages	
  enriched	
  with	
  RDFa	
  
§  RDF	
  inside	
  
    §  Data	
  created	
  by	
  SPARQL	
  INSERT	
  
    §  Data	
  queried	
  by	
  SPARQL	
  SELECT	
  
    §  Data	
  updated	
  by	
  SPARQL	
  DELETE	
  and	
  SELECT	
  
    §  Data	
  manipulated	
  by	
  user–friendly	
  forms	
  
§  Ongoing:	
  data	
  integraDon	
  with	
  ISIS	
  VŠE	
  and	
  other	
  department	
  
    applicaDons	
  
SPARQL:	
  Create	
  data	
  
INSERT	
  INTO	
  <http://keg.vse.cz/>	
  {	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  rdf:type	
  ical:Vevent	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:uid	
  ”1"	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:summary	
  ”IZI440"	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:dtstart	
  ”2011-­‐02-­‐28"	
  .	
  
}	
  
SPARQL:	
  Read	
  data	
  
SELECT	
  ?summary	
  ?uid	
  ?dtstart	
  ?dtend	
  
WHERE	
  {	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  rdf:type	
  ical:Vevent	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:uid	
  ?uid	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:summary	
  ?summary	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:dtstart	
  ?dtstart	
  .	
  
	
  	
  OPTIONAL	
  {	
  	
  
	
  	
  	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:dtend	
  ?dtend	
  .	
  	
  
	
  	
  }	
  
}	
  
SPARQL:	
  Update	
  data	
  
DELETE	
  {	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ?p	
  ?o	
  .	
  
}	
  
	
  
INSERT	
  INTO	
  <http://keg.vse.cz/>	
  {	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  rdf:type	
  ical:Vevent	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:uid	
  ”1"	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:summary	
  ”4IZ440"	
  .	
  
	
  	
  <http://keg.vse.cz/resource/event/1>	
  ical:dtstart	
  ”2011-­‐02-­‐28"	
  .	
  
}	
  
References	
  
§  hLp://dsic.zapisky.info/RDF/FOAF/parsingWithPHP/	
  
§  hLp://zapisky.info/?item=zverejnime-­‐akademicke-­‐projekty-­‐
    samozrejme-­‐semanDcky	
  

§  BOOK	
  –	
  John	
  Hebeler	
  (Author),	
  MaLhew	
  Fisher	
  (Author),	
  Ryan	
  
    Blace	
  (Author),	
  Andrew	
  Perez-­‐Lopez	
  (Author),	
  Mike	
  Dean	
  
    (Foreword):	
  Seman4c	
  Web	
  Programming,	
  Wiley,	
  2009	
  
QuesDons?	
  
Thank	
  you	
  

More Related Content

What's hot (20)

PPTX
SWT Lecture Session 2 - RDF
Mariano Rodriguez-Muro
 
PPT
Data in RDF
Emanuele Della Valle
 
PPTX
4 sw architectures and sparql
Mariano Rodriguez-Muro
 
PPT
Ist16-04 An introduction to RDF
Emanuele Della Valle
 
PPTX
Semantic web meetup – sparql tutorial
AdonisDamian
 
PPTX
The Semantic Web #4 - RDF (1)
Myungjin Lee
 
PPT
Ontologies in RDF-S/OWL
Emanuele Della Valle
 
PPTX
The Semantic Web #5 - RDF (2)
Myungjin Lee
 
PDF
An introduction to Semantic Web and Linked Data
Fabien Gandon
 
PPTX
FedX - Optimization Techniques for Federated Query Processing on Linked Data
aschwarte
 
PPTX
Name That Graph !
Fabien Gandon
 
PDF
Programming with LOD
Fumihiro Kato
 
PPTX
RDF, linked data and semantic web
Jose Emilio Labra Gayo
 
PPTX
Validating RDF data: Challenges and perspectives
Jose Emilio Labra Gayo
 
PPTX
ShEx by Example
Jose Emilio Labra Gayo
 
PPT
Querying the Semantic Web with SPARQL
Emanuele Della Valle
 
PPTX
Introduction to SPARQL
Jose Emilio Labra Gayo
 
PPT
SemanticWeb Nuts 'n Bolts
Rinke Hoekstra
 
PPTX
A Little SPARQL in your Analytics
Dr. Neil Brittliff
 
PDF
An introduction to Semantic Web and Linked Data
Gabriela Agustini
 
SWT Lecture Session 2 - RDF
Mariano Rodriguez-Muro
 
4 sw architectures and sparql
Mariano Rodriguez-Muro
 
Ist16-04 An introduction to RDF
Emanuele Della Valle
 
Semantic web meetup – sparql tutorial
AdonisDamian
 
The Semantic Web #4 - RDF (1)
Myungjin Lee
 
Ontologies in RDF-S/OWL
Emanuele Della Valle
 
The Semantic Web #5 - RDF (2)
Myungjin Lee
 
An introduction to Semantic Web and Linked Data
Fabien Gandon
 
FedX - Optimization Techniques for Federated Query Processing on Linked Data
aschwarte
 
Name That Graph !
Fabien Gandon
 
Programming with LOD
Fumihiro Kato
 
RDF, linked data and semantic web
Jose Emilio Labra Gayo
 
Validating RDF data: Challenges and perspectives
Jose Emilio Labra Gayo
 
ShEx by Example
Jose Emilio Labra Gayo
 
Querying the Semantic Web with SPARQL
Emanuele Della Valle
 
Introduction to SPARQL
Jose Emilio Labra Gayo
 
SemanticWeb Nuts 'n Bolts
Rinke Hoekstra
 
A Little SPARQL in your Analytics
Dr. Neil Brittliff
 
An introduction to Semantic Web and Linked Data
Gabriela Agustini
 

Viewers also liked (19)

PPTX
Triplestore and SPARQL
Lino Valdivia
 
PDF
Semantic Technology Solutions For Recovery Gov And Data Gov With Transparenc...
Mills Davis
 
PDF
The Web of Data: The W3C Semantic Web Initiative
National Information Standards Organization (NISO)
 
PPT
Semantic Web 2.0: Creating Social Semantic Information Spaces
John Breslin
 
PDF
W3C Tutorial on Semantic Web and Linked Data at WWW 2013
Fabien Gandon
 
PPTX
Intro to the Semantic Web Landscape - 2011
LeeFeigenbaum
 
PDF
Introduction To The Semantic Web
guest262aaa
 
PPTX
Semantic Web Landscape 2009
LeeFeigenbaum
 
PPT
The Semantic Web
ostephens
 
PPTX
Introduction to the Semantic Web
Tomek Pluskiewicz
 
PDF
Introduction to the Semantic Web
Marin Dimitrov
 
PDF
Semantic Computing Executive Briefing
Graeme Wood
 
ODP
Web 3.0 The Semantic Web
Hatem Mahmoud
 
PDF
Semantic Computing Executive Briefing
Semanticsoftware
 
PDF
Introduction to Semantic Computing
Semanticsoftware
 
PDF
2015 Upload Campaigns Calendar - SlideShare
SlideShare
 
PPTX
What to Upload to SlideShare
SlideShare
 
PDF
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
PDF
Getting Started With SlideShare
SlideShare
 
Triplestore and SPARQL
Lino Valdivia
 
Semantic Technology Solutions For Recovery Gov And Data Gov With Transparenc...
Mills Davis
 
The Web of Data: The W3C Semantic Web Initiative
National Information Standards Organization (NISO)
 
Semantic Web 2.0: Creating Social Semantic Information Spaces
John Breslin
 
W3C Tutorial on Semantic Web and Linked Data at WWW 2013
Fabien Gandon
 
Intro to the Semantic Web Landscape - 2011
LeeFeigenbaum
 
Introduction To The Semantic Web
guest262aaa
 
Semantic Web Landscape 2009
LeeFeigenbaum
 
The Semantic Web
ostephens
 
Introduction to the Semantic Web
Tomek Pluskiewicz
 
Introduction to the Semantic Web
Marin Dimitrov
 
Semantic Computing Executive Briefing
Graeme Wood
 
Web 3.0 The Semantic Web
Hatem Mahmoud
 
Semantic Computing Executive Briefing
Semanticsoftware
 
Introduction to Semantic Computing
Semanticsoftware
 
2015 Upload Campaigns Calendar - SlideShare
SlideShare
 
What to Upload to SlideShare
SlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
Getting Started With SlideShare
SlideShare
 
Ad

Similar to 2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs (20)

PDF
A Hands On Overview Of The Semantic Web
Shamod Lacoul
 
PPT
Introduction to RDF
Narni Rajesh
 
KEY
How RDFa works
JISC Netskills
 
KEY
RDFa Introductory Course Session 2/4 How RDFa
Platypus
 
PPT
A Semantic Multimedia Web (Part 2)
Raphael Troncy
 
PPTX
"RDFa - what, why and how?" by Mike Hewett and Shamod Lacoul
Shamod Lacoul
 
PDF
RDF and Java
Constantin Stan
 
PPTX
SWT Lecture Session 5 - RDFS
Mariano Rodriguez-Muro
 
PDF
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
Ontotext
 
PDF
Rdf data-model-and-storage
灿辉 葛
 
ODP
Riding the Semantic Web
Matthias Vandermaesen
 
PDF
RDF: what and why plus a SPARQL tutorial
Jerven Bolleman
 
PPTX
One day workshop Linked Data and Semantic Web
Victor de Boer
 
PPT
Introduction To RDF and RDFS
Nilesh Wagmare
 
PDF
Introduction to RDF & SPARQL
Open Data Support
 
PPT
A hands on overview of the semantic web
Marakana Inc.
 
PDF
Semantic Web Technology
Rathachai Chawuthai
 
PPTX
Apa itu RDF dan SPARQL sebagai alat bantu pada big Data
Eric199332
 
ODP
Semantic Web introduction
Graphity
 
A Hands On Overview Of The Semantic Web
Shamod Lacoul
 
Introduction to RDF
Narni Rajesh
 
How RDFa works
JISC Netskills
 
RDFa Introductory Course Session 2/4 How RDFa
Platypus
 
A Semantic Multimedia Web (Part 2)
Raphael Troncy
 
"RDFa - what, why and how?" by Mike Hewett and Shamod Lacoul
Shamod Lacoul
 
RDF and Java
Constantin Stan
 
SWT Lecture Session 5 - RDFS
Mariano Rodriguez-Muro
 
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
Ontotext
 
Rdf data-model-and-storage
灿辉 葛
 
Riding the Semantic Web
Matthias Vandermaesen
 
RDF: what and why plus a SPARQL tutorial
Jerven Bolleman
 
One day workshop Linked Data and Semantic Web
Victor de Boer
 
Introduction To RDF and RDFS
Nilesh Wagmare
 
Introduction to RDF & SPARQL
Open Data Support
 
A hands on overview of the semantic web
Marakana Inc.
 
Semantic Web Technology
Rathachai Chawuthai
 
Apa itu RDF dan SPARQL sebagai alat bantu pada big Data
Eric199332
 
Semantic Web introduction
Graphity
 
Ad

Recently uploaded (20)

PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 

2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs

  • 1. The  Seman)c  Web   RDF,  SPARQL  and  so0ware   APIs   4IZ440  Knowledge  Representa4on  and  Reasoning  on  the  WWW   Josef  Petrák  |  [email protected]    
  • 2. Worth  a  note   §  Open  Data  iniDave  around  world  and  Europe  open  staDsDcal  and   government  data,  usually  in  RDF  format.   §  It  has  several  success  stories   §  hLp://headtoweb.posterous.com/open-­‐data-­‐success-­‐stories   §  Google  is  integraDng  RDF  encoded  as  RDFa  in  pages  into  its  search   results.   §  UEP  is  not  behind  –  DIKE  research  group  KEG  started  Czech–Slovak   semanDc  iniDaDve  called  SemanDcs   §  And  we  have  a  RDF-­‐based  website  deployed,  see   hLp://keg.vse.cz/  
  • 3. Outline   §  RDF  representaDon  formats   §  Data  handling  approaches   §  So0ware  APIs  overview   §  Approaches  in  examples   §  MoDvaDon  example:  web  applicaDon  
  • 5. Syntaxes   §  RDF  has  several  syntaxes.   §  A  “graph”  is  the  reference  syntax.   §  The  W3C  endorsed  file  format  is  RDF/XML   §  Other  file  formats:   §  N-­‐Triples   §  N3   §  RDF/JSON   §  RDFa  
  • 6. RDF  graph     rdf:type   gd:Person   gd:name   John  Example   gd:affiliaDon   Sample  Corp.  Inc.   PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX gd: <http://rdf.data-vocabulary.org/#>
  • 7. RDF/XML   <rdf:RDF      xmlns:rdf=“http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”      xmlns:gd=“http://rdf.data-­‐vocabulary.org/#”>      <rdf:Resource>          <rdf:type  rdf:resource=“http://rdf.data-­‐vocabulary.org/#Person”/>          <gd:name>John  Example</gd:name>          <gd:affiliation>Sample  Corp.  Inc.</gd:affiliation>      </rdf:Resource>   </rdf:RDF>  
  • 8. RDF/XML  (shortened)   <rdf:RDF      xmlns:rdf=“http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”      xmlns:gd=“http://rdf.data-­‐vocabulary.org/#”>      <gd:Person>          <gd:name>John  Example</gd:name>          <gd:affiliation>Sample  Corp.  Inc.</gd:affiliation>      </gd:Person>   </rdf:RDF>  
  • 9. N3  NotaDon   @prefix  gd:  <http://rdf.data-­‐vocabulary.org/#>  .     []  a  gd:Person;      gd:name  “John  Example”;      gd:affiliation  “Sample  Corp.  Inc.”  .  
  • 10. N–Triples   _:a  <http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#type>      <http://rdf.data-­‐vocabulary.org/#Person>  .   _:a  <http://rdf.data-­‐vocabulary.org/#name>      “John  Example”  .   _:a  <http://rdf.data-­‐vocabulary.org/#affiliation>      “Sample  Corp.  Inc.”  .   §  Primarily  used  to  defined  RDF  test  cases   §  Subset  of  N3  NotaDon  
  • 11. RDF/JSON   {      “_:a“  :  {          “http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”  :  [              {                  “value“  :  “http://rdf.data-­‐vocabulary.org/#Person”,  “type“  :  “uri“              }          ],          “http://rdf.data-­‐vocabulary.org/#name”  :  [              {                  “value“  :  “John  Example“,  “type“  :  “literal“              }          ],          “http://rdf.data-­‐vocabulary.org/#affiliation”  :  [              {                  “value“  :  “Sample  Corp.  Inc.“,  “type“  :  “literal“              }          ]      }   }  
  • 12. RDFa   <html      xmlns=“http://www.w3.org/1999/xhtml”      xmlns:rdf=“http://www.w3.org/1999/02/22-­‐rdf-­‐syntax-­‐ns#”      xmlns:gd=“http://rdf.data-­‐vocabulary.org/#”>     <p  typeof=“gd:Person”>      <em  property=“gd:name”>John  Example</em>  is  working        at  <em  property=“gd:affiliation”>Sample  Corp.  Inc.</em>.   </p>     </html>  
  • 13. Resources  about  RDF  formats   §  RDF/XML   §  hLp://www.w3.org/TR/rdf-­‐syntax-­‐grammar/   §  N3  NotaDon   §  hLp://www.w3.org/DesignIssues/NotaDon3   §  hLp://www.w3.org/2000/10/swap/Primer   §  N–Triples   §  hLp://www.w3.org/TR/rdf-­‐testcases/#ntriples   §  RDF/JSON   §  hLp://n2.talis.com/wiki/RDF_JSON_SpecificaDon   §  RDFa   §  hLp://www.w3.org/TR/rdfa-­‐syntax/  
  • 14. Task  #1   1.  Use  Google  Data  Vocabulary   §  hLp://www.data-­‐vocabulary.org/Person/   2.  Created  a  NotaDon3  file  with  demo  data  about  people  
  • 16. RDF  models   §  Statement–centric   §  Working  with  triples  of  ?subject  ?predicate  ?object   §  Resource–centric   §  Working  with  resources  having  properDes  and  their  values   §  Ontology–centric   §  Working  with  classes,  properDes,  and  individuals  as  defined  in  selected   vocabulary/schema/ontology   §  Named  graph   §  Triples  belongs  to  a  graph  with  URI  name   §  Working  with  quads  of  ?graph  ?subject  ?predicate  ?object  
  • 18. Java   §  Jena   §  hLp://openjena.org/   §  hLp://sourceforge.net/projects/jena/   §  Sesame   §  hLp://www.openrdf.org/   §  Shellac  RDFa  Parser   §  hLps://github.com/shellac/java-­‐rdfa  
  • 19. PHP   §  RDF  API  for  PHP  (RAP)   §  hLp://www4.wiwiss.fu-­‐berlin.de/bizer/rdfapi/   §  hLp://sourceforge.net/projects/rdfapi-­‐php/   §  ARC2   §  hLp://arc.semsol.org/  
  • 20. Ruby   §  RDF.rb   §  hLp://rdf.rubyforge.org/   §  hLps://github.com/bendiken/rdf   §  Plus  various  modules  
  • 22. File-­‐read   §  Task:  Read  RDF  data  from  a  NotaDon3  file  format  into  memory   model.  
  • 23. Read  N3  (Jena)   InputStream  is  =        FileManager.get().open("samples/people.n3");                     Model  model  =  ModelFactory.createDefaultModel();   RDFReader  r  =  model.getReader("N3");   r.read(model,  is,  null);   is.close();  
  • 24. Read  N3  (RDF.rb)   repository  =  RDF::Repository.new     RDF::N3::Reader.open(‘samples/people.n3’)  {  |reader|      repository  <<    reader   }  
  • 25. Read  N3  (ARC2)   $parser  =  ARC2::getRDFParser();   $parser-­‐>parse(‘samples/people.n3');       $triples  =  $parser-­‐>getTriples();  
  • 26. Read  N3  (RAP)   $model  =  ModelFactory::getDefaultModel();   $model-­‐>load('samples/people.n3');   §  This  code  won’t  run,  because  there  is  N3Reader  bug.   §  Works  also  for  RDF/XML  and  N–Triples  formats.  
  • 27. Traverse  triples   §  Task:  Take  a  memory  model  and  list  all  or  parDcular  RDF  triples.  
  • 28. Traverse  triples  (Jena)   Model  model  =  ModelFactory.createDefaultModel();   //  Load  data  into  model                 StmtIterator  i  =  model.listStatements();   while  (i.hasNext())  {      Statement  stmt  =  i.nextStatement();      Resource  subject  =  stmt.getSubject();      Property  predicate  =  stmt.getPredicate();      RDFNode  object  =  stmt.getObject();                                //  Printing  out   }  
  • 29. Query  Model  (Jena)   Resource  rPerson  =  model.getResource("http://rdf.data-­‐ vocabulary.org/#Person");   Property  rName  =  model.getProperty("http://rdf.data-­‐vocabulary.org/ #name");     StmtIterator  si  =  model.listStatements(null,  RDF.type,  rPerson);   while  (si.hasNext())  {      Resource  r  =  si.nextStatement().getSubject();      StmtIterator  sii  =  model.listStatements(r,  rName,  (RDFNode)null);      if  (sii.hasNext())  {          System.out.println(sii.nextStatement().getObject().toString());      }   }  
  • 30. Traverse  triples  (RDF.rb)   repository  =  RDF::Repository.new   #  Load  data     repository.each_statement  {  |statement|      puts  statement   }  
  • 31. Query  model  (RDF.rb)   GD  =  RDF::Vocabulary.new('http://rdf.data-­‐vocabulary.org/#')     repository  =  RDF::Repository.new   #  Load  data     query  =  RDF::Query.new({      :person  =>  {          RDF.type  =>  GD.Person,  GD.name  =>  :name      }   })     query.execute(graph).each  do  |person|      puts  "name=#{person.name}"   end  
  • 32. Query  SPARQL  Endpoint   §  Task:  Query  a  SPARQL  endpoint  and  write  out  the  data.  E.g.  from   DBPedia,  write  one  random  blackboard  gag  wriLen  by  Bart   Simpson.  
  • 33. Query  SPARQL  Endpoint  (Jena)   String  qa  =  "PREFIX  skos:  <http://www.w3.org/2004/02/skos/core#>"                                  +  "PREFIX  dbpprop:  <http://dbpedia.org/property/>"                                  +  "PREFIX  dcterms:  <http://purl.org/dc/terms/>"                                  +  "PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-­‐schema#>"                                  +  "SELECT  ?gag  WHERE  {  "                                  +  "?series  skos:broader  <http://dbpedia.org/resource/ Category:The_Simpsons_episodes>  ."                                  +  "    ?episode  dcterms:subject  ?series  ."                                  +  "    ?episode  dbpprop:blackboard  ?gag  ."                                  +  "}"                                  +  "LIMIT  1000";   Query  q  =  QueryFactory.create(qa);                   QueryExecution  qe  =        QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql",  q);   ResultSet  rs  =  qe.execSelect();   ResultSetFormatter.out(System.out,  rs,  q);   qe.close();  
  • 34. Query  SPARQL  Endpoint  (RDF.rb)   sparql  =        SPARQL::Client.new("http://dbpedia.org/sparql")     result  =  sparql.query("SELECT  ?gag  WHERE  {        ?series  skos:broader  <http://dbpedia.org/resource/ Category:The_Simpsons_episodes>  .      ?episode  dcterms:subject  ?series  .      ?episode  dbpprop:blackboard  ?gag  .   }   LIMIT  1000")     puts  result[rand(result.length)][:gag]  
  • 35. Query  SPARQL  Endpoint  (RAP)   $client  =        ModelFactory::getSparqlClient("http://www.exampleSparqlService.net:2020/ example");     $query  =  new  ClientQuery();   $query-­‐>query(‘PREFIX  skos:  <http://www.w3.org/2004/02/skos/core#>    PREFIX  dbpprop:  <http://dbpedia.org/property/>    PREFIX  dcterms:  <http://purl.org/dc/terms/>    PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-­‐schema#>    SELECT  ?gag  WHERE  {        ?series  skos:broader  <http://dbpedia.org/resource/ Category:The_Simpsons_episodes>  .        ?episode  dcterms:subject  ?series  .        ?episode  dbpprop:blackboard  ?gag  .    }  LIMIT  1000’);   $result  =  $client-­‐>query($query);     foreach($result  as  $line){  echo($line['?gag']-­‐>toString());  }  
  • 36. Query  SPARQL  Endpoint  (ARC2)   $store  =        ARC2::getRemoteStore(          array('remote_store_endpoint'  =>  'http://dbpedia.org/sparql'));     $q  =  ‘PREFIX  skos:  <http://www.w3.org/2004/02/skos/core#>    PREFIX  dbpprop:  <http://dbpedia.org/property/>    PREFIX  dcterms:  <http://purl.org/dc/terms/>    PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-­‐schema#>    SELECT  ?gag  WHERE  {        ?series  skos:broader  <http://dbpedia.org/resource/ Category:The_Simpsons_episodes>  .        ?episode  dcterms:subject  ?series  .        ?episode  dbpprop:blackboard  ?gag  .    }  LIMIT  1000’;     $rows  =  $store-­‐>query($q,  'rows');    
  • 37. Task  #2   1.  Select  one  of  frameworks  (preferably  Jena)   2.  Load  data  from  your  NotaDon3  file   3.  Write  out  names  and  work  Dtles  of  people  
  • 39. Knowledge  Engineering  Group   Website   §  hLp://keg.vse.cz/   §  RDF  outside   §  Data  dumps  in  RDF/XML   §  Web  pages  enriched  with  RDFa   §  RDF  inside   §  Data  created  by  SPARQL  INSERT   §  Data  queried  by  SPARQL  SELECT   §  Data  updated  by  SPARQL  DELETE  and  SELECT   §  Data  manipulated  by  user–friendly  forms   §  Ongoing:  data  integraDon  with  ISIS  VŠE  and  other  department   applicaDons  
  • 40. SPARQL:  Create  data   INSERT  INTO  <http://keg.vse.cz/>  {      <http://keg.vse.cz/resource/event/1>  rdf:type  ical:Vevent  .      <http://keg.vse.cz/resource/event/1>  ical:uid  ”1"  .      <http://keg.vse.cz/resource/event/1>  ical:summary  ”IZI440"  .      <http://keg.vse.cz/resource/event/1>  ical:dtstart  ”2011-­‐02-­‐28"  .   }  
  • 41. SPARQL:  Read  data   SELECT  ?summary  ?uid  ?dtstart  ?dtend   WHERE  {      <http://keg.vse.cz/resource/event/1>  rdf:type  ical:Vevent  .      <http://keg.vse.cz/resource/event/1>  ical:uid  ?uid  .      <http://keg.vse.cz/resource/event/1>  ical:summary  ?summary  .      <http://keg.vse.cz/resource/event/1>  ical:dtstart  ?dtstart  .      OPTIONAL  {            <http://keg.vse.cz/resource/event/1>  ical:dtend  ?dtend  .        }   }  
  • 42. SPARQL:  Update  data   DELETE  {      <http://keg.vse.cz/resource/event/1>  ?p  ?o  .   }     INSERT  INTO  <http://keg.vse.cz/>  {      <http://keg.vse.cz/resource/event/1>  rdf:type  ical:Vevent  .      <http://keg.vse.cz/resource/event/1>  ical:uid  ”1"  .      <http://keg.vse.cz/resource/event/1>  ical:summary  ”4IZ440"  .      <http://keg.vse.cz/resource/event/1>  ical:dtstart  ”2011-­‐02-­‐28"  .   }  
  • 43. References   §  hLp://dsic.zapisky.info/RDF/FOAF/parsingWithPHP/   §  hLp://zapisky.info/?item=zverejnime-­‐akademicke-­‐projekty-­‐ samozrejme-­‐semanDcky   §  BOOK  –  John  Hebeler  (Author),  MaLhew  Fisher  (Author),  Ryan   Blace  (Author),  Andrew  Perez-­‐Lopez  (Author),  Mike  Dean   (Foreword):  Seman4c  Web  Programming,  Wiley,  2009