sparql 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3862bae6ddfbe07b6e3645ad068976f47922a45
4
- data.tar.gz: df1367b8faec7c1ee4827c236c28c64ee2711bf6
3
+ metadata.gz: 9ed52de8b3772ffc718813e0a7c9445fd37d27ec
4
+ data.tar.gz: b7aa4ec3157690796c0e12fc74bcf9328c740c2a
5
5
  SHA512:
6
- metadata.gz: 32aa953994369f6ff1a00abdd151033c887b496a53b706870918a1c9f883be3abca7a7386ebdc9bbb725b30b0e77196cc521d600a97101dbd7e1af251c0103ef
7
- data.tar.gz: c3a7762a66b864afb9409312e5cb4d9d55c6d76b71e418384716c5f94542cd310de1f3d801333d160a9c97969a90bab63d77c02d19e160bee74a667dc4416290
6
+ metadata.gz: 007315130ab3bc5f734e47c96d74f501460feb5e22229106b16c32dad35f24c59e35a47654fff1cc9f88610a8628bb43a33773cd812503800d954e52f3a3e1da
7
+ data.tar.gz: 697a8dde03ef5b117820d585f7e30d58c9f1e17eb8baa139f77d4f7260d6417dd6673e0d1e1bea181d2dd60f66ce8bc176dd7575d6caa056faeff03d103ed2ce
data/CREDITS CHANGED
@@ -1 +1,2 @@
1
1
  * Pius Uzamere <pius@alum.mit.edu>
2
+ * Tuan-Nhi Le <tuan-nhi.le@michivi.com>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 1.1.4
@@ -1,5 +1,15 @@
1
1
  require 'json'
2
2
 
3
+ ##
4
+ # Extensions for Ruby's `NilClass` class.
5
+ class NilClass
6
+
7
+ def evaluate(bindings, options = {})
8
+ self
9
+ end
10
+
11
+ end
12
+
3
13
  ##
4
14
  # Extensions for Ruby's `Object` class.
5
15
  class Object
@@ -289,6 +289,8 @@ module SPARQL; module Algebra
289
289
  operand
290
290
  when TrueClass, FalseClass, Numeric, String, DateTime, Date, Time
291
291
  RDF::Literal(operand)
292
+ when NilClass
293
+ nil
292
294
  else raise TypeError, "invalid SPARQL::Algebra::Operator operand: #{operand.inspect}"
293
295
  end
294
296
  end
@@ -16,7 +16,7 @@ module SPARQL; module Algebra
16
16
  NAME = :asc
17
17
 
18
18
  ##
19
- # Returns the evaluation of it's operand. Default comparison is in
19
+ # Returns the evaluation of its operand. Default comparison is in
20
20
  # ascending order. Ordering is applied in {Order}.
21
21
  #
22
22
  # @param [RDF::Query::Solution] bindings
@@ -52,7 +52,8 @@ module SPARQL; module Algebra
52
52
  when right.simple? && left.datatype == RDF::XSD.string && right.value == left.value
53
53
  RDF::Literal(-1)
54
54
 
55
- else raise TypeError, "unable to compare #{left.inspect} and #{right.inspect}"
55
+ else
56
+ left <=> right
56
57
  end
57
58
 
58
59
  when left.is_a?(RDF::URI) && right.is_a?(RDF::URI)
@@ -65,13 +66,22 @@ module SPARQL; module Algebra
65
66
  RDF::Literal(0)
66
67
 
67
68
  # SPARQL also fixes an order between some kinds of RDF terms that would not otherwise be ordered:
68
- # 2. Blank nodes
69
+
70
+ when left.nil? && !right.nil?
71
+ RDF::Literal(-1)
72
+ when right.nil?
73
+ RDF::Literal(1)
74
+
69
75
  when left.is_a?(RDF::Node) && right.is_a?(RDF::Term)
70
76
  RDF::Literal(-1)
71
77
  when right.is_a?(RDF::Node) && left.is_a?(RDF::Term)
72
78
  RDF::Literal(1)
73
79
 
74
- # 3. IRIs
80
+ when left.is_a?(RDF::Node) && right.is_a?(RDF::URI)
81
+ RDF::Literal(-1)
82
+ when right.is_a?(RDF::Node) && left.is_a?(RDF::URI)
83
+ RDF::Literal(1)
84
+
75
85
  when left.is_a?(RDF::URI) && right.is_a?(RDF::Term)
76
86
  RDF::Literal(-1)
77
87
  when right.is_a?(RDF::URI) && left.is_a?(RDF::Term)
@@ -32,26 +32,20 @@ module SPARQL; module Algebra
32
32
  # the resulting solution sequence
33
33
  # @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
34
34
  def execute(queryable, options = {}, &block)
35
+
35
36
  debug(options) {"Order"}
36
37
  @solutions = queryable.query(operands.last, options.merge(:depth => options[:depth].to_i + 1)).order do |a, b|
37
- operand(0).inject(false) do |memo, op|
38
+ operand(0).inject(0) do |memo, op|
38
39
  debug(options) {"(order) #{op.inspect}"}
39
- memo ||= begin
40
+ memo = begin
40
41
  a_eval = op.evaluate(a, options.merge(:queryable => queryable, :depth => options[:depth].to_i + 1)) rescue nil
41
42
  b_eval = op.evaluate(b, options.merge(:queryable => queryable, :depth => options[:depth].to_i + 1)) rescue nil
42
- comp = if a_eval.nil?
43
- RDF::Literal(-1)
44
- elsif b_eval.nil?
45
- RDF::Literal(1)
46
- elsif op.is_a?(RDF::Query::Variable)
47
- a_eval <=> b_eval
48
- else
49
- Operator::Compare.evaluate(a_eval, b_eval)
50
- end
43
+ comp = Operator::Compare.evaluate(a_eval, b_eval).to_i
51
44
  comp = -comp if op.is_a?(Operator::Desc)
52
- comp == 0 ? false : comp
53
- end
54
- end || 0 # They compare equivalently if there are no matches
45
+ comp
46
+ end if memo == 0
47
+ memo
48
+ end
55
49
  end
56
50
  @solutions.each(&block) if block_given?
57
51
  @solutions
@@ -1,7 +1,7 @@
1
1
  module SPARQL; module Algebra
2
2
  class Operator
3
3
  ##
4
- # The SPARQL GraphPattern `order` operator.
4
+ # The SPARQL GraphPattern `project` operator.
5
5
  #
6
6
  # @example
7
7
  # (select (?v)
@@ -36,7 +36,7 @@ module SPARQL; module Algebra
36
36
  operands[1..-1].each do |row|
37
37
  next unless row.is_a?(Array)
38
38
  bindings = row[1..-1].inject({}) do |memo, (var, value)|
39
- memo[var.to_sym] = value
39
+ memo[var.to_sym] = value unless value == :undef
40
40
  memo
41
41
  end
42
42
  @solutions << RDF::Query::Solution.new(bindings)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-01 00:00:00.000000000 Z
12
+ date: 2014-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf