Skip to content

Instantly share code, notes, and snippets.

@mcritchlow
Last active February 5, 2016 23:00
Show Gist options
  • Save mcritchlow/8147aa8ad643f5f34f90 to your computer and use it in GitHub Desktop.
Save mcritchlow/8147aa8ad643f5f34f90 to your computer and use it in GitHub Desktop.
A proposed DSL syntax for SPARQL 1.1 VALUES
it "should support VALUES" do
# should support single value construct (less verbose form)
expect(subject.select
.where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title])
.values([:title], ["This title", "Another title"]).to_s)
.to eq "SELECT * WHERE { ?s <http://purl.org/dc/terms/title> ?o . VALUES ?title { 'This title' 'Another title' } }"
# should support single value construct (general form)
expect(subject.select
.where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title])
.values([:title], ["This title", "Another title"]).to_s)
.to eq "SELECT * WHERE { ?s <http://purl.org/dc/terms/title> ?o . VALUES (?title) { ('This title') ('Another title') } }"
# should support multiple values
expect(subject.select
.where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title], [:s, RDF.type, :type])
.values([:type, :title], [RDF::URI('http://pcdm.org/models#Object'), "This title"], [RDF::URI('http://pcdm.org/models#Collection', 'Another title']).to_s)
.to eq "SELECT * WHERE { ?s <http://purl.org/dc/terms/title> ?o . ?s a ?type . VALUES (?type ?title) { (<http://pcdm.org/models#Object> 'This title') (<http://pcdm.org/models#Collection> 'Another title' } }"
# should support UNDEF for any value
expect(subject.select
.where([:s, RDF::URI('http://purl.org/dc/terms/title'), :title], [:s, RDF.type, :type])
.values([:type, :title], [UNDEF, "This title"], [RDF::URI('http://pcdm.org/models#Collection'), UNDEF]).to_s)
.to eq "SELECT * WHERE { ?s <http://purl.org/dc/terms/title> ?o . ?s a ?type . VALUES (?type ?title) { (UNDEF 'This title') (<http://pcdm.org/models#Collection> UNDEF) } }"
end
@mcritchlow
Copy link
Author

re: ruby-rdf/sparql-client#37

Questions/thoughts:

  • While #values matches the spec, it's so overloaded I'm wary of using it in this context. Curious what you think. Could be something more verbose, like #inline_values, #inline_data or ...
  • VALUES supports a few different syntax options for a VALUES query with a single value. The first two examples show both forms. Should the single value use the general form as well?
  • VALUES can also iterate over the results: SELECT * WHERE { ?s <http://purl.org/dc/terms/title> ?o . } } VALUES (?title) { ('This title') ('Another title') Still thinking about how best to make this distinction in the DSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment