Module: Sinatra::SPARQL::Helpers
- Defined in:
- vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sinatra/sparql.rb
Overview
Helper methods.
Instance Method Summary collapse
-
#service_description(options = {}) ⇒ RDF::Graph
This is useful when a GET request is performed against a SPARQL endpoint and no query is performed.
Instance Method Details
#service_description(options = {}) ⇒ RDF::Graph
This is useful when a GET request is performed against a SPARQL endpoint and no query is performed. Provide a set of datasets, including a default dataset along with optional triple count, dump location, and description of the dataset.
The results are serialized using content negotiation. For text/html, authors should generate RDFa for the serivce description directly.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sinatra/sparql.rb', line 30 def service_description( = {}) repository = [:repository] g = RDF::Graph.new sd = RDF::URI("http://www.w3.org/ns/sparql-service-description#") void = RDF::URI("http://rdfs.org/ns/void#") node = RDF::Node.new g << [node, RDF.type, sd.join("#Service")] g << [node, sd.join("#endpoint"), [:endpoint] || url("/sparql")] g << [node, sd.join("#supportedLanguage"), sd.join("#SPARQL11Query")] # Result formats, both RDF and SPARQL Results. # FIXME: We should get this from the avaliable serializers g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/RDF_XML")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/Turtle")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/RDFa")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/N-Triples")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/SPARQL_Results_XML")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/SPARQL_Results_JSON")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/SPARQL_Results_CSV")] g << [node, sd.join("#resultFormat"), RDF::URI("http://www.w3.org/ns/formats/SPARQL_Results_TSV")] # Features g << [node, sd.join("#feature"), sd.join("#DereferencesURIs")] # Datasets ds = RDF::Node.new g << [node, sd.join("#defaultDataset"), ds] g << [ds, RDF.type, sd.join("#Dataset")] # Contexts if repository.is_a?(RDF::Enumerable) graph_names = {} repository.each do |statement| graph_names[statement.graph_name] ||= 0 graph_names[statement.graph_name] += 1 end graph_names.each do |name, count| bn = RDF::Node.new if name # Add named graphs as namedGraphs g << [ds, sd.join("#namedGraph"), bn] g << [bn, RDF.type, sd.join("#NamedGraph")] g << [bn, sd.join("#name"), name] graph = RDF::Node.new g << [bn, sd.join("#graph"), graph] bn = graph else # Default graph g << [ds, sd.join("#defaultGraph"), bn] g << [bn, RDF.type, sd.join("#Graph")] end g << [bn, void.join("#triples"), count] end end g end |