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.



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
310
311
312
313
314
315
# File 'lib/nimono/cabocha_lib.rb', line 271

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.



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

def additional_info
  @additional_info
end

#c_formObject (readonly)

Returns the value of attribute c_form.



256
257
258
# File 'lib/nimono/cabocha_lib.rb', line 256

def c_form
  @c_form
end

#c_typeObject (readonly)

Returns the value of attribute c_type.



257
258
259
# File 'lib/nimono/cabocha_lib.rb', line 257

def c_type
  @c_type
end

#chunkObject (readonly)

Returns the value of attribute chunk.



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

def chunk
  @chunk
end

#featureObject (readonly)

Returns the value of attribute feature.



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

def feature
  @feature
end

#feature_listObject (readonly)

Returns the value of attribute feature_list.



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

def feature_list
  @feature_list
end

#feature_list_sizeObject (readonly)

Returns the value of attribute feature_list_size.



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

def feature_list_size
  @feature_list_size
end

#neObject (readonly)

Returns the value of attribute ne.



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

def ne
  @ne
end

#normalized_surfaceObject (readonly)

Returns the value of attribute normalized_surface.



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

def normalized_surface
  @normalized_surface
end

#o_formObject (readonly)

Returns the value of attribute o_form.



258
259
260
# File 'lib/nimono/cabocha_lib.rb', line 258

def o_form
  @o_form
end

#posObject (readonly)

Returns the value of attribute pos.



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

def pos
  @pos
end

#pos1Object (readonly)

Returns the value of attribute pos1.



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

def pos1
  @pos1
end

#pos2Object (readonly)

Returns the value of attribute pos2.



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

def pos2
  @pos2
end

#pos3Object (readonly)

Returns the value of attribute pos3.



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

def pos3
  @pos3
end

#pronunciationObject (readonly)

Returns the value of attribute pronunciation.



260
261
262
# File 'lib/nimono/cabocha_lib.rb', line 260

def pronunciation
  @pronunciation
end

#readingObject (readonly)

Returns the value of attribute reading.



259
260
261
# File 'lib/nimono/cabocha_lib.rb', line 259

def reading
  @reading
end

#surfaceObject (readonly)

Returns the value of attribute surface.



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

def surface
  @surface
end

Instance Method Details

#to_sObject



317
318
319
# File 'lib/nimono/cabocha_lib.rb', line 317

def to_s
  @surface
end