Module: Kasabi::Sparql

Defined in:
lib/kasabi/api/sparql.rb

Overview

Module providing a SPARQL client library, support for parsing SPARQL query responses into Ruby objects and other useful behaviour

Defined Under Namespace

Classes: Client

Constant Summary collapse

SPARQL_RESULTS_XML =
"application/sparql-results+xml"
SPARQL_RESULTS_JSON =
"application/sparql-results+json"
SYMMETRIC_BOUNDED_DESCRIPTION =

Includes all statements along both in-bound and out-bound arc paths

See n2.talis.com/wiki/Bounded_Descriptions_in_RDF

<<-EOL
CONSTRUCT {?uri ?p ?o . ?s ?p2 ?uri .} WHERE { {?uri ?p ?o .} UNION {?s ?p2 ?uri .} }
EOL
LABELLED_BOUNDED_DESCRIPTION =

Similar to Concise Bounded Description but includes labels for referenced resources

See n2.talis.com/wiki/Bounded_Descriptions_in_RDF

<<-EOL
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
CONSTRUCT {
   ?uri ?p ?o . 
   ?o rdfs:label ?label . 
   ?o rdfs:comment ?comment . 
   ?o <http://www.w3.org/2004/02/skos/core#prefLabel> ?plabel . 
   ?o rdfs:seeAlso ?seealso.
} WHERE {
  ?uri ?p ?o . 
  OPTIONAL { 
    ?o rdfs:label ?label .
  } 
  OPTIONAL {
    ?o <http://www.w3.org/2004/02/skos/core#prefLabel> ?plabel . 
  } 
  OPTIONAL {
    ?o rdfs:comment ?comment . 
  } 
  OPTIONAL { 
    ?o rdfs:seeAlso ?seealso.
  }
}    
EOL
SYMMETRIC_LABELLED_BOUNDED_DESCRIPTION =

Derived from both the Symmetric and Labelled Bounded Descriptions. Includes all in-bound and out-bound arc paths, with labels for any referenced resources.

See n2.talis.com/wiki/Bounded_Descriptions_in_RDF

<<-EOL
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
CONSTRUCT {
  ?uri ?p ?o . 
  ?o rdfs:label ?label . 
  ?o rdfs:comment ?comment . 
  ?o rdfs:seeAlso ?seealso. 
  ?s ?p2 ?uri . 
  ?s rdfs:label ?label . 
  ?s rdfs:comment ?comment . 
  ?s rdfs:seeAlso ?seealso.
} WHERE { 
  { ?uri ?p ?o . 
    OPTIONAL { 
      ?o rdfs:label ?label .
    } 
    OPTIONAL {
      ?o rdfs:comment ?comment .
    } 
    OPTIONAL {
      ?o rdfs:seeAlso ?seealso.
    } 
  } 
  UNION {
    ?s ?p2 ?uri . 
    OPTIONAL {
      ?s rdfs:label ?label .
    } 
    OPTIONAL {
      ?s rdfs:comment ?comment .
    } 
    OPTIONAL {
      ?s rdfs:seeAlso ?seealso.
    } 
  } 
}    
EOL
DESCRIPTIONS =
{
  :cbd => "DESCRIBE ?uri",
  :scbd => SYMMETRIC_BOUNDED_DESCRIPTION,
  :lcbd => LABELLED_BOUNDED_DESCRIPTION,
  :slcbd => SYMMETRIC_LABELLED_BOUNDED_DESCRIPTION
}