Class: YandexMystem::Base
- Inherits:
-
Object
- Object
- YandexMystem::Base
- Defined in:
- lib/yandex_mystem.rb
Class Method Summary collapse
-
.stem(text) ⇒ Object
TODO add -i.
Class Method Details
.stem(text) ⇒ Object
TODO add -i
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yandex_mystem.rb', line 7 def self.stem(text) exec = Array(command).tap do |c| c << '-e utf-8 -n' end.join(' ') data = Open3.popen3(exec) do |stdin, stdout, stderr| stdin.write text stdin.close #stderr.read stdout.read end data = data.scan(/^([^\{]+)\{(.+)\}$/).map do |(word, words)| words = words.split('|').select do |w| !(w =~ /.+\?\?$/) end [word, words] end.flatten(1) Hash[*data] end |