Class: Nimono::Token

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/nimono/cabocha_lib.rb

Overview

‘Token’ is a wrapper class for the ‘cabocha_token_t’ structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lptr) ⇒ Token

Returns a new instance of Token.



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/nimono/cabocha_lib.rb', line 265

def initialize(lptr)
  super(lptr)
  @pointer = lptr
  if self[:surface]
    @surface = self[:surface].force_encoding(Encoding.default_external)
  end
  if self[:normalized_surface]
    @normalized_surface = self[:normalized_surface].force_encoding(Encoding.default_external)
  end
  if self[:feature]
    @feature = self[:feature].force_encoding(Encoding.default_external)
  end
  if self[:feature_list_size]
    @feature_list_size = self[:feature_list_size]
  end
  if self[:ne]
    @ne = self[:ne].force_encoding(Encoding.default_external)
  end
  if self[:additional_info]
    @additional_info = self[:additional_info].force_encoding(Encoding.default_external)
  end
  if self[:chunk]
    self[:chunk].null? ? nil : @chunk = Nimono::Chunk.new(self[:chunk])
  end

  if self[:feature_list_size] < 0
    raise CabochaError.new "Feature list size error"
  else
    if self[:feature_list].null?
      @feature_list = [].freeze
    else
      @feature_list = self[:feature_list].get_array_of_string(0, self[:feature_list_size]).each{|s| s.force_encoding(Encoding.default_external)}.freeze
    end
  end

  @pos           = @feature_list[0]
  @pos1          = @feature_list[1]
  @pos2          = @feature_list[2]
  @pos3          = @feature_list[3]
  @c_form        = @feature_list[4]
  @c_type        = @feature_list[5]
  @o_form        = @feature_list[6]
  @reading       = @feature_list[7]
  @pronunciation = @feature_list[8]
end

Instance Attribute Details

#additional_infoObject (readonly)

Returns the value of attribute additional_info.



243
244
245
# File 'lib/nimono/cabocha_lib.rb', line 243

def additional_info
  @additional_info
end

#c_formObject (readonly)

Returns the value of attribute c_form.



250
251
252
# File 'lib/nimono/cabocha_lib.rb', line 250

def c_form
  @c_form
end

#c_typeObject (readonly)

Returns the value of attribute c_type.



251
252
253
# File 'lib/nimono/cabocha_lib.rb', line 251

def c_type
  @c_type
end

#chunkObject (readonly)

Returns the value of attribute chunk.



244
245
246
# File 'lib/nimono/cabocha_lib.rb', line 244

def chunk
  @chunk
end

#featureObject (readonly)

Returns the value of attribute feature.



239
240
241
# File 'lib/nimono/cabocha_lib.rb', line 239

def feature
  @feature
end

#feature_listObject (readonly)

Returns the value of attribute feature_list.



240
241
242
# File 'lib/nimono/cabocha_lib.rb', line 240

def feature_list
  @feature_list
end

#feature_list_sizeObject (readonly)

Returns the value of attribute feature_list_size.



241
242
243
# File 'lib/nimono/cabocha_lib.rb', line 241

def feature_list_size
  @feature_list_size
end

#neObject (readonly)

Returns the value of attribute ne.



242
243
244
# File 'lib/nimono/cabocha_lib.rb', line 242

def ne
  @ne
end

#normalized_surfaceObject (readonly)

Returns the value of attribute normalized_surface.



238
239
240
# File 'lib/nimono/cabocha_lib.rb', line 238

def normalized_surface
  @normalized_surface
end

#o_formObject (readonly)

Returns the value of attribute o_form.



252
253
254
# File 'lib/nimono/cabocha_lib.rb', line 252

def o_form
  @o_form
end

#posObject (readonly)

Returns the value of attribute pos.



246
247
248
# File 'lib/nimono/cabocha_lib.rb', line 246

def pos
  @pos
end

#pos1Object (readonly)

Returns the value of attribute pos1.



247
248
249
# File 'lib/nimono/cabocha_lib.rb', line 247

def pos1
  @pos1
end

#pos2Object (readonly)

Returns the value of attribute pos2.



248
249
250
# File 'lib/nimono/cabocha_lib.rb', line 248

def pos2
  @pos2
end

#pos3Object (readonly)

Returns the value of attribute pos3.



249
250
251
# File 'lib/nimono/cabocha_lib.rb', line 249

def pos3
  @pos3
end

#pronunciationObject (readonly)

Returns the value of attribute pronunciation.



254
255
256
# File 'lib/nimono/cabocha_lib.rb', line 254

def pronunciation
  @pronunciation
end

#readingObject (readonly)

Returns the value of attribute reading.



253
254
255
# File 'lib/nimono/cabocha_lib.rb', line 253

def reading
  @reading
end

#surfaceObject (readonly)

Returns the value of attribute surface.



237
238
239
# File 'lib/nimono/cabocha_lib.rb', line 237

def surface
  @surface
end

Instance Method Details

#to_sObject



311
312
313
# File 'lib/nimono/cabocha_lib.rb', line 311

def to_s
  @surface
end