Class: Desmoservice::WordDistribution

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWordDistribution

Returns a new instance of WordDistribution.



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

def initialize
  @words = Hash.new
  @tagged_terms = Hash.new
end

Instance Attribute Details

#tagged_termsObject (readonly)

Returns the value of attribute tagged_terms.



4
5
6
# File 'lib/word_distribution.rb', line 4

def tagged_terms
  @tagged_terms
end

#wordsObject (readonly)

Returns the value of attribute words.



4
5
6
# File 'lib/word_distribution.rb', line 4

def words
  @words
end

Instance Method Details

#parse_json(json_string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/word_distribution.rb', line 11

def parse_json(json_string)
  data = JSON.parse(json_string)
  if data.has_key?('lexiedistribution')
    if data['lexiedistribution'].has_key?('lexieArray')
      data['lexiedistribution']['lexieArray'].each do |v|
        word = Word.new(v['id'], v['value'])
        v['codeArray'].each {|id| word.term_ids << id}
        @words[word.id] = word
      end
    end
    if data['lexiedistribution'].has_key?('sourceMap')
      data['lexiedistribution']['sourceMap'].each_value do |v|
        tagged_term = TaggedTerm.new(v)
        @tagged_terms[tagged_term.id] = tagged_term
      end
    end
  end
end