Class: WordBloom::Quality
- Inherits:
-
Object
- Object
- WordBloom::Quality
- Defined in:
- lib/word-bloom/quality.rb
Instance Attribute Summary collapse
-
#correlations ⇒ Object
readonly
Returns the value of attribute correlations.
-
#languages ⇒ Object
Returns the value of attribute languages.
Class Method Summary collapse
Instance Method Summary collapse
- #build_metrics ⇒ Object
-
#initialize ⇒ Quality
constructor
A new instance of Quality.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Quality
Returns a new instance of Quality.
12 13 14 15 |
# File 'lib/word-bloom/quality.rb', line 12 def initialize @correlations = {} @languages = [] end |
Instance Attribute Details
#correlations ⇒ Object (readonly)
Returns the value of attribute correlations.
18 19 20 |
# File 'lib/word-bloom/quality.rb', line 18 def correlations @correlations end |
#languages ⇒ Object
Returns the value of attribute languages.
17 18 19 |
# File 'lib/word-bloom/quality.rb', line 17 def languages @languages end |
Class Method Details
.build_all ⇒ Object
5 6 7 8 9 10 |
# File 'lib/word-bloom/quality.rb', line 5 def self.build_all qual = self.new qual.languages = Scorer::all_languages qual.build_metrics qual end |
Instance Method Details
#build_metrics ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/word-bloom/quality.rb', line 20 def build_metrics require 'word-bloom/filter-builder' languages.each do |lang| Scorer::load_filter(lang) end languages.each_with_index do |lang, index| languages.drop(index + 1).each do |other_lang| @correlations[[lang, other_lang]] = (Scorer::filter_for(lang) & Scorer::filter_for(other_lang)).to_f / FilterBuilder::BITFIELD_WIDTH end end end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/word-bloom/quality.rb', line 35 def to_s width = languages.map{|lang| lang.to_s.length}.max + 2 col_sep = " " ([([" " * width] + languages.map{|lang| lang.to_s.rjust(width)}).join(col_sep)] + languages.map do |left| ([left.to_s.ljust(width)] + languages.map do |right| if num = @correlations[[left, right]] || @correlations[[right, left]] "%#{width}f" % num else "-" * width end end ).join(col_sep) end).join("\n") end |