Module: DataMining

Defined in:
lib/log_analysis/data_mining.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.execute(transform_data, min_conf, min_sup) ⇒ Object

Your code goes here…



8
9
10
11
12
# File 'lib/log_analysis/data_mining.rb', line 8

def self.execute(transform_data, min_conf, min_sup)
  File.open(LogAnalysis::TRANSFORM_DATA_PATH, 'w+') { |f| transform_data.keys.each { |e| f.puts(transform_data[e].map { |i| i.is_a?(Array) ? i.join(' ') : i }.join(' -1 ').concat(' -1 -2')) } }
  system("java -jar #{LogAnalysis::JAR_FILE_PATH} run SPADE #{LogAnalysis::TRANSFORM_DATA_PATH} #{LogAnalysis::RULE_FILE_PATH} #{min_sup}%")
  rule_gen(get_seq(File.read(LogAnalysis::RULE_FILE_PATH)), min_conf)
end

.get_seq(seq_str) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/log_analysis/data_mining.rb', line 41

def self.get_seq(seq_str)
  seq = seq_str.split("\n")
  seq.each_with_object([]) do |s, arr|
    split_seq = s.split('-1')
    arr.push([split_seq[0..-2], split_seq[-1][-1].to_f])
  end
end

.rule_gen(seqs, min_conf) ⇒ Object



14
15
16
# File 'lib/log_analysis/data_mining.rb', line 14

def self.rule_gen(seqs, min_conf)
  seqs.each_with_object([]) { |seq, arr| seqs.each { |sub| arr.push([seq[0], sub[0], seq[1] / sub[1]]) if sub[0] != seq[0] && sub_seq?(sub[0], seq[0]) && seq[1] / sub[1] >= min_conf } }
end

.sub?(str, sub) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/log_analysis/data_mining.rb', line 34

def self.sub?(str, sub)
  mark_sub = 0
  sub.split(' ').each { |char| mark_sub += 1 if str.include?(char) }

  mark_sub == sub.split(' ').size
end

.sub_seq?(first, second) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/log_analysis/data_mining.rb', line 18

def self.sub_seq?(first, second)
  ptr = 0
  first.each do |sub|
    return false if ptr >= second.size

    (ptr..second.size - 1).each do |n|
      if sub?(second[n], sub)
        ptr = n + 1
        break
      end
      return false if ptr == second.size - 1
    end
  end
  true
end