Class: StreetAddressCh::ChStateMachine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ ChStateMachine

Returns a new instance of ChStateMachine.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/streetaddressch/chstatemachine.rb', line 18

def initialize(text)
	@text = text
	@length = text.jlength
	@result_list = Array.new
	@sm = Statemachine.build do 
		trans :start_st, :province_ev, :province_st, :shift_word
		trans :start_st, :city_ev, :city_st, :shift_word
		trans :province_st, :city_ev, :city_st, :shift_word
		trans :province_st, :district_ev, :district_st, :shift_word
		trans :city_st, :street_ev, :street_st, :shift_word
		trans :city_st, :district_ev, :district_st, :shift_word
		trans :district_st, :district_ev, :district_st, :shift_word
		trans :district_st, :street_ev, :street_st, :shift_word
      context ChStatemachineContext.new
	end
    @sm.context.statemachine = self
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



16
17
18
# File 'lib/streetaddressch/chstatemachine.rb', line 16

def length
  @length
end

#result_listObject

Returns the value of attribute result_list.



17
18
19
# File 'lib/streetaddressch/chstatemachine.rb', line 17

def result_list
  @result_list
end

#textObject (readonly)

Returns the value of attribute text.



16
17
18
# File 'lib/streetaddressch/chstatemachine.rb', line 16

def text
  @text
end

Instance Method Details

#is_english?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/streetaddressch/chstatemachine.rb', line 35

def is_english?
	return @text.length == @text.jlength
end

#tokenizeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/streetaddressch/chstatemachine.rb', line 38

def tokenize
	tmp =Array.new
	@text.each_char do |char|
	  tmp << char
		case char
			when ''
				@sm.province_ev tmp
				tmp=[]
			when ''
				@sm.city_ev tmp
				tmp=[]
			when ''
				@sm.district_ev tmp
				tmp=[]
			when ''
				@sm.street_ev tmp
				tmp=[]
		end
	end
	@result_list
end