Class: CodeModels::InfoExtraction::TermsBreaker

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language_specific_logic) ⇒ TermsBreaker

Returns a new instance of TermsBreaker.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/codemodels/info_extraction.rb', line 11

def initialize(language_specific_logic)
  @language_specific_logic = language_specific_logic
  @sequences = Hash.new {|h,k| 
    h[k] = Hash.new {|h,k| 
      h[k]=0
    } 
  }
  @inv_sequences = Hash.new {|h,k| 
    h[k] = Hash.new {|h2,k2| 
      h2[k2]=0
    } 
  }
end

Instance Attribute Details

#inv_sequencesObject

Returns the value of attribute inv_sequences.



9
10
11
# File 'lib/codemodels/info_extraction.rb', line 9

def inv_sequences
  @inv_sequences
end

#sequencesObject

Returns the value of attribute sequences.



9
10
11
# File 'lib/codemodels/info_extraction.rb', line 9

def sequences
  @sequences
end

Class Method Details

.from_context(language_specific_logic, context) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/codemodels/info_extraction.rb', line 25

def self.from_context(language_specific_logic,context)
  values_map = context.values_map
  instance = new(language_specific_logic)  
  values_map.each do |value,c|
    value = value.to_s.strip
    if language_specific_logic.terms_containing_value?(value)
      words = language_specific_logic.to_words(value)        
      first_words = words[0...-1]
      instance.inv_sequences[words[0].downcase][:start] += c
      first_words.each_with_index do |w,i|
        instance.sequences[w.downcase][words[i+1].downcase] += c
        instance.inv_sequences[words[i+1].downcase][w.downcase] += c
      end
      last_word = words.last
      instance.sequences[last_word.downcase][:end] += c
    else
      # who cares, it will be never considered for composed names...
    end
  end
  instance
end

Instance Method Details

#terms_in_value(value) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/codemodels/info_extraction.rb', line 47

def terms_in_value(value)
  value = value.to_s.strip
  if @language_specific_logic.terms_containing_value?(value)
    words = @language_specific_logic.to_words(value)
    group_words_in_terms(words).map{|w| w.downcase}     
  else
    [value]
  end
end