Class: Fuzzy::Scorer::TermSet

Inherits:
Struct
  • Object
show all
Defined in:
lib/fuzzy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#termsObject

Returns the value of attribute terms

Returns:

  • (Object)

    the current value of terms



7
8
9
# File 'lib/fuzzy.rb', line 7

def terms
  @terms
end

#weightObject

Returns the value of attribute weight

Returns:

  • (Object)

    the current value of weight



7
8
9
# File 'lib/fuzzy.rb', line 7

def weight
  @weight
end

Instance Method Details

#cleaned_termsObject



8
9
10
# File 'lib/fuzzy.rb', line 8

def cleaned_terms
  terms.flat_map{|t| t.parameterize.split('-')}.to_set
end

#token_weight(total_weight) ⇒ Object



12
13
14
# File 'lib/fuzzy.rb', line 12

def token_weight total_weight
  weight.fdiv(total_weight * terms.size)
end

#tokens(total_weight) ⇒ Object



16
17
18
19
20
# File 'lib/fuzzy.rb', line 16

def tokens total_weight
  cleaned_terms.map do |term|
    Token.new term, token_weight(total_weight)
  end
end