lib/kuromoji/core.rb in kuromoji-ruby-0.0.2 vs lib/kuromoji/core.rb in kuromoji-ruby-0.0.3
- old
+ new
@@ -35,23 +35,25 @@
def reading(sentence)
process(:getReading, sentence)
end
def tokenize_with_hash(sentence)
+ result = []
+ return result if sentence.nil?
list = @tokenizer.tokenize(sentence)
iterator = list.iterator
- result = []
while iterator.has_next
item = iterator.next
result << item.to_kuromoji_hash
end
result
end
def process(method, sentence)
+ tokenized = {}
+ return tokenized if sentence.nil?
list = @tokenizer.tokenize(sentence)
iterator = list.iterator
- tokenized = {}
while iterator.has_next
item = iterator.next
tokenized[item.surface_form] = item.send(method)
end
tokenized
\ No newline at end of file