Class: Freql::Words

Inherits:
Object
  • Object
show all
Defined in:
lib/freql/words.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#wordsObject (readonly)

Returns the value of attribute words.



19
20
21
# File 'lib/freql/words.rb', line 19

def words
  @words
end

Class Method Details

.by_lang(lang = :en, size: :small) ⇒ Object



12
13
14
15
16
# File 'lib/freql/words.rb', line 12

def by_lang lang = :en, size: :small
  w = self.new
  w.extract_lang_file lang, size: size
  return w
end

Instance Method Details

#extract_lang_file(lang, size:) ⇒ Object



38
39
40
41
42
# File 'lib/freql/words.rb', line 38

def extract_lang_file lang, size:
  BinData.read_and_unpack_lang( lang, size: size ) do |lang_data|
    @words = lang_data
  end
end

#lookup(word) ⇒ Object



21
22
23
# File 'lib/freql/words.rb', line 21

def lookup word
  @words[word]
end

#lookup_zipf(word) ⇒ Object



25
26
27
28
# File 'lib/freql/words.rb', line 25

def lookup_zipf word
  r = lookup(word)
  r && CB.cb_to_zipf(r)
end

#query(*words) ⇒ Object



30
31
32
# File 'lib/freql/words.rb', line 30

def query *words
  @words.slice(*words)
end

#query_zipf(*words) ⇒ Object



34
35
36
# File 'lib/freql/words.rb', line 34

def query_zipf *words
  query(*words).transform_values {|v| CB.cb_to_zipf(v) }
end