lib/r_nlp/tf.rb in r_nlp-0.1.4 vs lib/r_nlp/tf.rb in r_nlp-0.1.5
- old
+ new
@@ -5,10 +5,14 @@
class Tf
# compatible with ja or en
attr_reader :lang
def initialize(lang)
@lang = lang
+ unless lang == 'ja' || lang == 'en'
+ puts "lang #{@lang} is not compatible."
+ exit
+ end
end
def count(text)
tf = Hash.new
if @lang == 'ja'
nm = Natto::MeCab.new
@@ -21,21 +25,18 @@
tf[word.surface] += 1
end
end
end
elsif @lang == 'en'
- text.split(" ").each do |line|
+ text.split("\n").each do |line|
line.split(" ").each do |word|
if tf[word] == nil
tf[word] = 1
else
tf[word] += 1
end
end
end
- else
- puts "lang #{@lang} is not compatible."
- exit
end
return tf
end
end
end