Class: Rseg

Inherits:
Object
  • Object
show all
Includes:
RsegEngine, RsegFilter, Singleton
Defined in:
lib/rseg.rb

Constant Summary

Constants included from RsegEngine

RsegEngine::LETTER_SYMBOLS

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRseg

Returns a new instance of Rseg.



48
49
50
51
52
53
# File 'lib/rseg.rb', line 48

def initialize
  @input = ''
  @words = []
  init_engines
  init_filters
end

Class Method Details

.dict_path=(path) ⇒ Object



23
24
25
# File 'lib/rseg.rb', line 23

def dict_path=(path)
  RsegEngine::Dict.dict_path = path
end

.loadObject



32
33
34
35
# File 'lib/rseg.rb', line 32

def load
  Rseg.instance
  nil
end

.remote_segment(input) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rseg.rb', line 37

def remote_segment(input)
  begin
    response = Net::HTTP.post_form(URI.parse('http://127.0.0.1:4100/seg'), :input => input)
    response.code == '200' ? response.body.split(' ') : 
        ["Can't connect to http://localhost:4100\nUse rseg_server to start it"]
  rescue
    ["Can't connect to http://localhost:4100\nUse rseg_server to start it"]
  end
end

.segment(input) ⇒ Object



27
28
29
30
# File 'lib/rseg.rb', line 27

def segment(input)
  Rseg.instance.input = input
  Rseg.instance.segment
end

Instance Method Details

#input=(input) ⇒ Object



55
56
57
# File 'lib/rseg.rb', line 55

def input=(input)
  @input = input
end

#segmentObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rseg.rb', line 59

def segment
  @words = []
  
  @input.chars.each do |origin|
    char = filter(origin)
    process(char, origin)
  end
  
  process(:symbol, '')
  @words
end