Thanks!
class Translater
require "rubygems"
require "rmmseg"
include RMMSeg
RMMSeg::Config.max_word_length = 7
RMMSeg::Config.algorithm = :complex
RMMSeg::Config.dictionaries = [["dict/chars.dic", true],
["dict/words.dic", false],
["dict/desc.dic", false],
["dict/identity.dic", false],
["dict/name.dic", false],
]
Word = {}
File.open(File.join(File.dirname(__FILE__), "dict",
"word_china_english.trans")).each do |line|
arr = line.split(" ")
arr[1] = arr[0] unless arr[1]
Word[arr[0]] = Word[arr[1]]
end
def self.segment(phrase)
p RMMSeg::Config.max_word_length
RMMSeg::segment(phrase)
end
def self.run(phrase)
words = segment(phrase)
translation = ""
words.each do |word|
translation += Word[word].to_s + " "
end
translation
end
end
The actual problem is : why can not i use methods of some libray
(rmmseg in this exam) in rails.
I can use it in simple ruby program.
In rails, I encapsulate that method(segment) by a ruby class
(Translater), and put the source in folder lib/
when using it in helper functions, problem occurs like this:
undefined method `segment' for RMMSeg:Module
Thanks for your help again!
On 12月2日, 下午5时51分, Frederick Cheung <
frederick.che...@gmail.com>
wrote: