Class: LightModels::InfoExtraction::TermsBreaker

Inherits:
Object
  • Object
show all
Defined in:
lib/lightmodels/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.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lightmodels/info_extraction.rb', line 9

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.



7
8
9
# File 'lib/lightmodels/info_extraction.rb', line 7

def inv_sequences
  @inv_sequences
end

#sequencesObject

Returns the value of attribute sequences.



7
8
9
# File 'lib/lightmodels/info_extraction.rb', line 7

def sequences
  @sequences
end

Class Method Details

.from_context(language_specific_logic, context) ⇒ Object



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

def self.from_context(language_specific_logic,context)
	ser_context = LightModels::Serialization.jsonize_obj(context)
	values_map = LightModels::QuerySerialized.collect_values_with_count(ser_context)
	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



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

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