class SimString::Database

Attributes

feature_extractor[R]

Public Class Methods

load(file_path) click to toggle source
# File lib/simstring_pure.rb, line 175
def load(file_path)
  m = Marshal.load(File.read(file_path))
end
new(feature_extractor) click to toggle source
# File lib/simstring_pure.rb, line 182
def initialize(feature_extractor)
  @strings = Set.new
  @feature_extractor = feature_extractor
  @feature_set_size_to_string_map = {}
  @feature_set_size_and_feature_to_string_map = {}
end

Public Instance Methods

add(string) click to toggle source
# File lib/simstring_pure.rb, line 189
def add(string)
  if !@strings.include?(string)
    @strings << string

    features = feature_extractor.features(string)
    feature_set_size = features.size

    # update @feature_set_size_to_string_map
    @feature_set_size_to_string_map[feature_set_size] ||= Set.new
    @feature_set_size_to_string_map[feature_set_size] << string

    # update @feature_set_size_and_feature_to_string_map
    @feature_set_size_and_feature_to_string_map[feature_set_size] ||= {}
    features.each do |feature|
      @feature_set_size_and_feature_to_string_map[feature_set_size][feature] ||= Set.new
      @feature_set_size_and_feature_to_string_map[feature_set_size][feature] << string
    end
  end
  nil
end
lookup_strings_by_feature_set_size_and_feature(size, feature) click to toggle source
# File lib/simstring_pure.rb, line 218
def lookup_strings_by_feature_set_size_and_feature(size, feature)
  return Set.new if @feature_set_size_and_feature_to_string_map[size].nil?
  @feature_set_size_and_feature_to_string_map[size][feature] || Set.new
end
max_feature_size() click to toggle source
# File lib/simstring_pure.rb, line 214
def max_feature_size
  @feature_set_size_to_string_map.keys.max
end
min_feature_size() click to toggle source
# File lib/simstring_pure.rb, line 210
def min_feature_size
  @feature_set_size_to_string_map.keys.min
end
save(file_path) click to toggle source
# File lib/simstring_pure.rb, line 223
def save(file_path)
  File.open(file_path, 'w') {|f| f.write(Marshal.dump(self)) }
end