Class: YandexMystem::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex_mystem.rb

Direct Known Subclasses

Raw, Simple

Class Method Summary collapse

Class Method Details

.commandObject



23
24
25
26
27
28
# File 'lib/yandex_mystem.rb', line 23

def self.command
  @command ||= begin
    path = Pathname.new(__FILE__) + '../../bin/'
    path + "mystem-#{command_postfix}"
  end
end

.command_postfixObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/yandex_mystem.rb', line 30

def self.command_postfix
  @command_postfix ||= case RUBY_PLATFORM
    when /(win|w)32$/
      'win.exe'
    when /32.+linux$|i[46]86.+linux$/
      'linux-32'
    when /64.+linux$/
      'linux-64'
    when /darwin/
      raise 'Mystem 3.0 does not support Max OS X.'
    when /freebsd/
      'bsd'
    else
      raise 'Unknown OS'
    end
end

.stem(text) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yandex_mystem.rb', line 11

def self.stem(text)
  exec = [command, self::ARGUMENTS].join(' ')

  data = Open3.popen3(exec) do |stdin, stdout, _|
    stdin.write text
    stdin.close
    stdout.read
  end

  parse(data)
end