Skip to content

Commit

Permalink
Merge branch 'master' into feature/reset-to-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Apr 30, 2024
2 parents 24af9f9 + 180c818 commit ca04308
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
matrix:
ruby: [2.6, 2.7, '3.0', 3.1, 3.2, ruby-head, jruby]
gemfile:
- Gemfile
- Gemfile-pure
- Gemfile&
steps:
- name: Clone repository
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions Gemfile-pure
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ end
group :debug do
gem 'shotgun'
gem "byebug", platforms: :mri
gem "pry"
end
15 changes: 8 additions & 7 deletions lib/sparql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ def parse_response(response, **options)
parse_rdf_serialization(response, **options)
end
end

##
# @param [String, Hash] json
# @return [<RDF::Query::Solutions>]
Expand Down Expand Up @@ -546,19 +545,21 @@ def self.parse_json_bindings(json, nodes = {})
# @see https://www.w3.org/TR/rdf-sparql-json-res/#variable-binding-results
def self.parse_json_value(value, nodes = {})
return nil if value == {}

case value['type'].to_sym
when :bnode
nodes[id = value['value']] ||= RDF::Node.new(id)
when :uri
RDF::URI.new(value['value'])
when :literal
if value['xml:lang'] or value['lang']
RDF::Literal.new(value['value'], :language => value['xml:lang'])
else
RDF::Literal.new(value['value'], :datatype => value['datatype'])
end
RDF::Literal.new(value['value'], datatype: value['datatype'], language: value['xml:lang'])
when :'typed-literal'
RDF::Literal.new(value['value'], :datatype => value['datatype'])
RDF::Literal.new(value['value'], datatype: value['datatype'])
when :triple
s = parse_json_value(value['value']['subject'], nodes)
p = parse_json_value(value['value']['predicate'], nodes)
o = parse_json_value(value['value']['object'], nodes)
RDF::Statement(s, p, o)
else nil
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/sparql/client/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def expects_statements?
end

def to_s
graph = " GRAPH #{SPARQL::Client.serialize_uri(self.options[:graph])} " if self.options[:graph]
query_text = 'INSERT {'
query_text += graph + + ' {'
graph = self.options[:graph] ? " GRAPH #{SPARQL::Client.serialize_uri(self.options[:graph])} " : ""
query_text = "INSERT #{!self.options[:graph] ? 'DATA' : ''} {"
query_text += graph + ' {' if self.options[:graph]
query_text += "\n"
query_text += RDF::NTriples::Writer.buffer { |writer| @data.each { |d| writer << d } }
query_text += '}' if self.options[:graph]
Expand Down
10 changes: 7 additions & 3 deletions spec/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,20 @@

context "with unions" do
it "supports pattern arguments" do
expect(subject.select.where([:s, :p, :o]).union([:s, :p, :o]).to_s).to eq "SELECT * WHERE { ?s ?p ?o . } UNION { ?s ?p ?o . }"
#expect(subject.select.where([:s, :p, :o]).union([:s, :p, :o]).to_s).to eq "SELECT * WHERE { ?s ?p ?o . } UNION { ?s ?p ?o . }" # original expect
# NCBO UNION expect
expect(subject.select.where([:s, :p, :o]).union([:s, :p, :o]).to_s).to eq "SELECT * WHERE { ?s ?p ?o . { ?s ?p ?o . } }"
end

it "supports query arguments" do
subquery = subject.select.where([:s, :p, :o])
expect(subject.select.where([:s, :p, :o]).union(subquery).to_s).to eq "SELECT * WHERE { ?s ?p ?o . } UNION { ?s ?p ?o . }"
# NCBO UNION expect
expect(subject.select.where([:s, :p, :o]).union(subquery).to_s).to eq "SELECT * WHERE { ?s ?p ?o . { ?s ?p ?o . } }"
end

it "supports block" do
expect(subject.select.where([:s, :p, :o]).union {|q| q.where([:s, :p, :o])}.to_s).to eq "SELECT * WHERE { ?s ?p ?o . } UNION { ?s ?p ?o . }"
# NCBO UNION expect
expect(subject.select.where([:s, :p, :o]).union {|q| q.where([:s, :p, :o])}.to_s).to eq "SELECT * WHERE { ?s ?p ?o . { ?s ?p ?o . } }"
end

it "rejects mixed arguments" do
Expand Down
3 changes: 2 additions & 1 deletion spec/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
it "supports the GRAPH modifier" do
[subject.insert_data(RDF::Graph.new, graph: 'http://example.org/'),
subject.insert_data(RDF::Graph.new).graph('http://example.org/')].each do |example|
expect(example.to_s).to eq "INSERT DATA { GRAPH <http://example.org/> {\n}}\n"
# NCBO INSERT DATA expect
expect(example.to_s).to eq "INSERT { GRAPH <http://example.org/> {\n}}\n"
end
end
end
Expand Down

0 comments on commit ca04308

Please sign in to comment.