Commit 545923c9 authored by Coraline Ehmke's avatar Coraline Ehmke

Renamed to cohort detector

parent 9cfb4b61
......@@ -4,12 +4,12 @@ require 'poro_plus'
require "snuffle/version"
require "snuffle/cohort"
require "snuffle/cohort_detector"
require "snuffle/node"
require "snuffle/file_parser"
require "snuffle/elements/hash"
require "snuffle/elements/string"
require "snuffle/util/histogram"
require "snuffle/detectors/data_clump"
module Snuffle
end
......@@ -7,39 +7,23 @@ module Snuffle
attr_accessor :node
def self.materialize(nodes=[])
nodes.each.map{|string_node| new(string_node) }.select{|h| h.pairs.present?}
nodes.each.map{|string_node| new(string_node) }#.select{|h| h.pairs.present?}
end
def initialize(node)
self.node = node
end
def pairs
@pairs ||= values.zip(keys).inject({}){|hash, pair| hash[pair[0]] = pair[1]; hash}
end
def keys
node.children.map{ |child| child.children.first.name }
end
def values
node.children.map{ |child| child.children.last.name }
end
def key_matrix
keys.sort.map(&:hash)
node.children.map{ |child| child.children.last.name }.select{|v| v.is_a?(Symbol)}
end
def value_matrix
values.sort.map(&:hash)
end
def sorted_pairs
keys.sort.inject({}) { |h, k| h[k] = pairs[k]; h}
end
def inspect
sorted_pairs
values
end
end
......
......@@ -49,7 +49,7 @@ module Snuffle
end
def strings
Element::Hash.materialize(nodes.where(type: :string).to_a)
Element::String.materialize(nodes.where(type: :dstr).to_a)
end
end
......
......@@ -44,6 +44,10 @@ class Customer
{name: customer_name, business: company_name}
end
def letterhead
"#{customer_name}\r#{company_name}"
end
def address
string = ""
string << self.customer_name
......
require 'spec_helper'
require 'pry'
describe Snuffle::Detectors::DataClump do
describe Snuffle::CohortDetector do
let(:file) { File.read("spec/fixtures/program_2.rb") }
let(:parser) { Snuffle::FileParser.new(file) }
let(:detector) { Snuffle::Detectors::DataClump.new(parser.hashes) }
let(:detector) { Snuffle::CohortDetector.new(parser.hashes) }
describe "weighting" do
......
require 'snuffle'
def reload!
load "lib/snuffle/node.rb"
load "lib/snuffle/detectors/data_clump.rb"
end
def file
File.open("spec/fixtures/program_2.rb", "r").read
end
def file_parser
@file_parser ||= Snuffle::FileParser.new(file)
@file_parser ||= Snuffle::FileParser.new(File.open("spec/fixtures/program_2.rb", "r").read)
end
def hashes
file_parser.hashes
def hash_clump
@hash_clump ||= Snuffle::CohortDetector.new(file_parser.hashes)
end
def clump
@clump ||= Snuffle::Detectors::DataClump.new(hashes)
def string_clump
@string_clump ||= Snuffle::CohortDetector.new(file_parser.strings)
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment