Class: TokenMap
- Inherits:
-
Object
- Object
- TokenMap
- Defined in:
- lib/libsvm_preprocessor/token_map.rb
Instance Attribute Summary collapse
-
#hash_of_ngrams ⇒ Object
readonly
Returns the value of attribute hash_of_ngrams.
Instance Method Summary collapse
-
#initialize ⇒ TokenMap
constructor
A new instance of TokenMap.
- #token_map(ary_of_ngrams, testing: false) ⇒ Object
Constructor Details
#initialize ⇒ TokenMap
Returns a new instance of TokenMap.
5 6 7 8 |
# File 'lib/libsvm_preprocessor/token_map.rb', line 5 def initialize @hash_of_ngrams = {} @current_ngram_id = 0 end |
Instance Attribute Details
#hash_of_ngrams ⇒ Object (readonly)
Returns the value of attribute hash_of_ngrams.
3 4 5 |
# File 'lib/libsvm_preprocessor/token_map.rb', line 3 def hash_of_ngrams @hash_of_ngrams end |
Instance Method Details
#token_map(ary_of_ngrams, testing: false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/libsvm_preprocessor/token_map.rb', line 10 def token_map(ary_of_ngrams, testing: false) if !testing ary_of_ngrams.each { |ngram| @hash_of_ngrams[ngram] ||= next_ngram_id } ary_of_ngrams.map { |ngram| { @hash_of_ngrams[ngram] => ngram } } else ary_of_ngrams.map do |ngram| { @hash_of_ngrams[ngram] => ngram } end.select do |hash| hash.keys.first end end end |