Class: Rseg

Inherits:
Object
  • Object
show all
Includes:
RsegEngine, RsegFilter, Singleton
Defined in:
lib/rseg_harry.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.



47
48
49
50
51
52
# File 'lib/rseg_harry.rb', line 47

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

Class Method Details

.dict_path=(path) ⇒ Object



22
23
24
# File 'lib/rseg_harry.rb', line 22

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

.loadObject



31
32
33
34
# File 'lib/rseg_harry.rb', line 31

def load
  Rseg.instance
  nil
end

.remote_segment(input) ⇒ Object



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

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



26
27
28
29
# File 'lib/rseg_harry.rb', line 26

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

Instance Method Details

#input=(input) ⇒ Object



54
55
56
# File 'lib/rseg_harry.rb', line 54

def input=(input)
  @input = input
end

#segmentObject



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

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