Skip to content

SPARQL queries for Annotation Graphs

Paolo Ciccarese edited this page Apr 7, 2016 · 8 revisions

Retrieve all triples of a given graph

PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX oa: <http://www.w3.org/ns/oa#> 

SELECT ?s ?p ?o {
  GRAPH <GRAPH-URI>
 {  
     ?s ?p ?o . 
 }
}

Get graph that contains a specific annotation

PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX ao: <http://www.w3.org/ns/oa#> 

SELECT DISTINCT ?g {
  GRAPH ?g
  {  
     <ANNOTATION-URI> rdfs:type ao:Annotation .  
  }
}

Get all triples of a graph that contains a specific annotation

PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX ao: <http://www.w3.org/ns/oa#> 

SELECT * {
  GRAPH ?g
  {  
    ?s ?p ?o . 
    <ANNOTATION-URI> rdfs:type ao:Annotation . 
  }
}

Get graph that contains annotation for an article

PREFIX rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX oa: <http://www.w3.org/ns/oa#> 

SELECT DISTINCT ?g {
  GRAPH ?g
  {  
     ?a rdfs:type oa:Annotation . 
     ?a oa:hasTarget ?target .
     ?target oa:hasSource ?source .
     ?source <http://purl.org/vocab/frbr/core#embodimentOf> ?e .
     ?e <http://purl.org/spar/fabio#hasPubMedId> '10679938'.
  }
}