Module: RuleGeneration
- Defined in:
- lib/log_analysis/rule_generation.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- JAR_FILE_PATH =
File.join(File.dirname(__FILE__), './files/spmf.jar')
- TRANSFORM_DATA_PATH =
"transform_data_#{Time.now.strftime('%Y%m%d')}.txt".freeze
- RULE_FILE_PATH =
"output_#{Time.now.strftime('%Y%m%d')}.txt".freeze
- MAP_URI_FILE_PATH =
"map_uri_#{Time.now.strftime('%Y%m%d')}.txt".freeze
Class Method Summary collapse
-
.execute(transform_data, min_conf, min_sup) ⇒ Object
Your code goes here…
- .get_seq(seq_str) ⇒ Object
- .rule_gen(seqs, min_conf) ⇒ Object
- .sub?(str, sub) ⇒ Boolean
- .sub_seq?(first, second) ⇒ Boolean
Class Method Details
.execute(transform_data, min_conf, min_sup) ⇒ Object
Your code goes here…
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/log_analysis/rule_generation.rb', line 13 def self.execute(transform_data, min_conf, min_sup) File.open(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 #{JAR_FILE_PATH} run SPADE #{TRANSFORM_DATA_PATH} #{RULE_FILE_PATH} #{min_sup}%") result = rule_gen(get_seq(File.read(RULE_FILE_PATH)), min_conf) map_uri = File.read(MAP_URI_FILE_PATH).split(' ') result.map do |rule| seq, sub, rea = rule [seq.map { |i| map_uri[i.to_i] }, sub.map { |i| map_uri[i.to_i] }, rea] end end |
.get_seq(seq_str) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/log_analysis/rule_generation.rb', line 52 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
25 26 27 |
# File 'lib/log_analysis/rule_generation.rb', line 25 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
45 46 47 48 49 50 |
# File 'lib/log_analysis/rule_generation.rb', line 45 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/log_analysis/rule_generation.rb', line 29 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 |