class NameDeduplicationParameters
This class encapsulates parameters that are needed for name-deduplication in Rosette API.
Attributes
names[RW]
List of Name objects to be de-duplicated
rosette_options[RW]
Rosette API options (optional, should be a hash)
threshold[RW]
Threshold for determining cluster size
Public Instance Methods
load_params()
click to toggle source
Converts this class to Hash with its keys in lower CamelCase.
Returns the new Hash.
# File name_deduplication_parameters.rb, line 44 def load_params validate_params to_hash .select { |_key, value| value } .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) } end
to_hash()
click to toggle source
Converts this class to Hash.
Returns the new Hash.
# File name_deduplication_parameters.rb, line 54 def to_hash { names: @names.map(&:load_param), threshold: @threshold, options: @rosette_options } end
validate_params()
click to toggle source
Validates the parameters by checking if name1 and name2 are instances of a String or NameParameter
.
# File name_deduplication_parameters.rb, line 27 def validate_params param_msg = 'names must be an array of name_parameter' raise BadRequestError.new(param_msg) unless @names.instance_of? Array float_msg = 'threshold must be a float' thresh_msg = 'threshold must be in the range of 0 to 1' if @threshold raise BadRequestError.new(float_msg) unless @threshold.is_a?(Float) raise BadRequestError.new(thresh_msg) if @threshold.negative? || @threshold > 1 end opt_msg = 'rosette_options can only be an instance of a Hash' raise BadRequestError.new(opt_msg) if @rosette_options && !(@rosette_options.is_a? Hash) end
Protected Instance Methods
initialize(names, threshold, options = {})
click to toggle source
# File name_deduplication_parameters.rb, line 16 def initialize(names, threshold, options = {}) # :notnew: options = { rosette_options: nil }.update options @names = names @threshold = threshold @rosette_options = options[:rosette_options] end