Module: Evoc::Util

Defined in:
lib/evoc/util.rb

Class Method Summary collapse

Class Method Details

.lattice(nodes, filter: nil) ⇒ Object

helper function to generate a lattice so we can easily come up with tests for the closed rules mining examples nodes: [[‘a’,],[‘b’,],[‘c’,]] first elem is item name second elem is the txes where this item changes



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/evoc/util.rb', line 8

def self.lattice(nodes,filter: nil)
  (1..nodes.size).each do |n|
    nodes.combination(n).each do |comb|
      # [['a',[1,2]],['b',[2,3]]]
      union = comb.map(&:first).join(',')
      frequency = comb.map(&:second).inject(&:&).size
      if filter =~ union
        if frequency > 0
          printf("%#{nodes.size*2}s",[union,frequency].join(':'))
        end
      end
    end
    puts
  end
end

.nodes2txstore(nodes) ⇒ Object

helper function for generating a txstore from the following format

[‘a’,],[‘b’,],[‘c’,]

(same structure as used for lattice creation)



27
28
29
30
31
32
33
34
35
# File 'lib/evoc/util.rb', line 27

def self.nodes2txstore(nodes)
  txes = nodes.map(&:second).inject(&:|)
  store = Evoc::TxStore.new
  txes.each do |id|
    items = nodes.select {|n| n.second.include?(id)}.map(&:first)
    store << Evoc::Tx.new(id: id, items: items)
  end
  return(store)
end