bmg 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed20ed6694b6def37acde708b49e546e93057fba
4
- data.tar.gz: 11112aa3a19301a61ab63f33d3d8e336f35fb770
3
+ metadata.gz: 4972b019d398ba2be5f7cb73765f120849e0365e
4
+ data.tar.gz: 153fbe99bc8947f23919686afe475d955674d8e5
5
5
  SHA512:
6
- metadata.gz: 027be153336eea476e1a6958f8114e234c399627a416f76e17e96dcce519191ba01ac183132d728b80d39733d84806a4bda1fcae1a5a0486ea509bd7f02c5fe9
7
- data.tar.gz: cfc2a227c20a55746da3dade630ded932ba037b7105513b01992939329fcc8bf927a172fb5a3043ed428c01c4f8273df1a21340dd000bc8feb66e1788a32153b
6
+ metadata.gz: e39d912e26e824d715375c90420a182a6b35de4cadd5d7afb668fe3c761ac19f3bd9384b2843c935b21184fce7ce524a874783298778b43b2360333e2ab47471
7
+ data.tar.gz: 6d738735211d6d22e60fce0210bc188d5abf37304e3c7f1311a27b7051fe05919cb691c00c771eeb4fa6b5566ebe9cf5498e2d0c018d39a0dce205cd44a07870
data/lib/bmg/algebra.rb CHANGED
@@ -7,7 +7,9 @@ module Bmg
7
7
  :autosummarize,
8
8
  :constants,
9
9
  :extend,
10
+ :group,
10
11
  :image,
12
+ :matching,
11
13
  :project,
12
14
  :rename,
13
15
  :restrict,
@@ -59,6 +61,15 @@ module Bmg
59
61
  end
60
62
  protected :_extend
61
63
 
64
+ def group(attrs, as = :group, options = {})
65
+ _group self.type.group(attrs, as), attrs, as, options
66
+ end
67
+
68
+ def _group(type, attrs, as, options)
69
+ Operator::Group.new(type, self, attrs, as, options)
70
+ end
71
+ protected :_group
72
+
62
73
  def image(right, as = :image, on = [], options = {})
63
74
  _image self.type.image(right, as, on, options), right, as, on, options
64
75
  end
data/lib/bmg/operator.rb CHANGED
@@ -70,9 +70,10 @@ require_relative 'operator/autosummarize'
70
70
  require_relative 'operator/autowrap'
71
71
  require_relative 'operator/constants'
72
72
  require_relative 'operator/extend'
73
+ require_relative 'operator/group'
73
74
  require_relative 'operator/image'
75
+ require_relative 'operator/matching'
74
76
  require_relative 'operator/project'
75
77
  require_relative 'operator/rename'
76
78
  require_relative 'operator/restrict'
77
79
  require_relative 'operator/union'
78
- require_relative 'operator/matching'
@@ -0,0 +1,88 @@
1
+ module Bmg
2
+ module Operator
3
+ #
4
+ # Group operator.
5
+ #
6
+ # Groups some operand attributes as a new Relation-valued
7
+ # attribute
8
+ #
9
+ class Group
10
+ include Operator::Unary
11
+
12
+ DEFAULT_OPTIONS = {
13
+
14
+ # Whether we need to convert each group as an Array,
15
+ # instead of keeping a Relation instance
16
+ array: false
17
+
18
+ }
19
+
20
+ def initialize(type, operand, attrs, as, options)
21
+ @type = type
22
+ @operand = operand
23
+ @attrs = attrs
24
+ @as = as
25
+ @options = DEFAULT_OPTIONS.merge(options)
26
+ end
27
+
28
+ protected
29
+
30
+ attr_reader :attrs, :as, :options
31
+
32
+ public
33
+
34
+ def each(&bl)
35
+ index = Hash.new{|h,k| h[k] = k.merge(as => empty_group) }
36
+ operand.each do |tuple|
37
+ key = TupleAlgebra.allbut(tuple, attrs)
38
+ sub = TupleAlgebra.project(tuple, attrs)
39
+ index[key][as].operand << sub
40
+ end
41
+ if options[:array]
42
+ index.values.each do |tuple|
43
+ tuple[as] = tuple[as].to_a
44
+ yield(tuple)
45
+ end
46
+ else
47
+ index.values.each(&bl)
48
+ end
49
+ end
50
+
51
+ def to_ast
52
+ [ :group, operand.to_ast, attrs.dup, as, options.dup ]
53
+ end
54
+
55
+ protected ### optimization
56
+
57
+ def _restrict(type, predicate)
58
+ top, bottom = predicate.and_split([as])
59
+ if top == predicate
60
+ super
61
+ else
62
+ op = operand
63
+ op = op.restrict(bottom)
64
+ op = op.group(attrs, as, options)
65
+ op = op.restrict(top)
66
+ op
67
+ end
68
+ end
69
+
70
+ protected ### inspect
71
+
72
+ def args
73
+ [ attrs, as, options ]
74
+ end
75
+
76
+ private
77
+
78
+ def empty_group
79
+ Relation::InMemory.new(group_type, Set.new)
80
+ end
81
+
82
+ def group_type
83
+ type.project(attrs)
84
+ end
85
+
86
+ end # class Extend
87
+ end # module Operator
88
+ end # module Bmg
@@ -1,9 +1,10 @@
1
1
  module Bmg
2
2
  module Operator
3
3
  #
4
- # Image operator.
4
+ # Matching operator.
5
5
  #
6
- # Extends each tuple with its image in right.
6
+ # Filters tuples of left operand to those matching at least
7
+ # one tuple in right operand.
7
8
  #
8
9
  class Matching
9
10
  include Operator::Binary
data/lib/bmg/type.rb CHANGED
@@ -33,6 +33,10 @@ module Bmg
33
33
  ANY
34
34
  end
35
35
 
36
+ def group(attrs, as)
37
+ ANY
38
+ end
39
+
36
40
  def image(right, as, on, options)
37
41
  ANY
38
42
  end
data/lib/bmg/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 7
5
- TINY = 1
4
+ MINOR = 8
5
+ TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -114,6 +114,7 @@ files:
114
114
  - lib/bmg/operator/autowrap.rb
115
115
  - lib/bmg/operator/constants.rb
116
116
  - lib/bmg/operator/extend.rb
117
+ - lib/bmg/operator/group.rb
117
118
  - lib/bmg/operator/image.rb
118
119
  - lib/bmg/operator/matching.rb
119
120
  - lib/bmg/operator/project.rb