Class: StreetAddressCh::ChStateMachine
- Inherits:
-
Object
- Object
- StreetAddressCh::ChStateMachine
- Defined in:
- lib/streetaddressch/chstatemachine.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#result_list ⇒ Object
Returns the value of attribute result_list.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ ChStateMachine
constructor
A new instance of ChStateMachine.
- #is_english? ⇒ Boolean
- #tokenize ⇒ Object
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
#length ⇒ Object (readonly)
Returns the value of attribute length.
16 17 18 |
# File 'lib/streetaddressch/chstatemachine.rb', line 16 def length @length end |
#result_list ⇒ Object
Returns the value of attribute result_list.
17 18 19 |
# File 'lib/streetaddressch/chstatemachine.rb', line 17 def result_list @result_list end |
#text ⇒ Object (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
35 36 37 |
# File 'lib/streetaddressch/chstatemachine.rb', line 35 def is_english? return @text.length == @text.jlength end |
#tokenize ⇒ Object
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 |