Module: Nimono::CabochaLib

Extended by:
FFI::Library
Included in:
Cabocha
Defined in:
lib/nimono/cabocha_lib.rb

Overview

Module ‘CabochaLib` is a ruby extension for CaboCha libraries using Ruby-FFI.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

CABOCHA_PATH =
'CABOCHA_PATH'.freeze

Class Method Summary collapse

Class Method Details

.cabocha_libraryString

Returns the absolute path to the CaboCha library.

Returns:

  • (String)

    absolute path to the CaboCha library



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nimono/cabocha_lib.rb', line 18

def self.cabocha_library
  if ENV[CABOCHA_PATH]
    File.absolute_path(ENV[CABOCHA_PATH])
  else
    host_os = RbConfig::CONFIG['host_os'].downcase

    lib_name = case host_os
               when /mswin|mingw/ # /mswin|msys|mingw|cygwin|bccwin|wince|emc/
                 require 'win32/registry'
                 begin
                   path = nil
                   Win32::Registry::HKEY_CURRENT_USER.open('Software\Cabocha') {|r| path = r['cabocharc'].split('etc').first}
                   File.join(path, "bin\\libcabocha.dll")
                 rescue
                   raise LoadError, "Please set #{CABOCHA_PATH} to the full path to libcabocha.dll"
                 end
               when /darwin/, /linux/, /solaris|bsd/
                 require 'open3'
                 host_os =~ /darwin/ ? ext = 'dylib' : ext = 'so'
                 begin
                   Open3.popen3('cabocha-config --libs') {|i, o, e, t|
                     i.close
                     tokens = o.read.split
                     File.absolute_path(File.join(tokens[0][2..-1], "lib#{tokens[1][2..-1]}.#{ext}"))
                   }
                 rescue
                   raise LoadError, "Please set #{CABOCHA_PATH} to the full path to libcabocha.#{ext}"
                 end
               else
                 raise CabochaError.new "unknown os: #{host_os.inspect}"
               end
  end
end

.included(klass) ⇒ Object



12
13
14
# File 'lib/nimono/cabocha_lib.rb', line 12

def self.included(klass)
  klass.extend ClassMethods
end