Class: Nimono::Chunk

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

Overview

‘Chunk’ is a wrapper class for the ‘cabocha_chunk_t’ structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lptr) ⇒ Chunk

Returns a new instance of Chunk.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/nimono/cabocha_lib.rb', line 194

def initialize(lptr)
  super(lptr)
  @pointer = lptr
  if self[:additional_info]
    @additional_info = self[:additional_info].force_encoding(Encoding.default_external)
  end
  if self[:link]
    @link = self[:link]
  end
  if self[:head_pos]
    @head_pos = self[:head_pos]
  end
  if self[:func_pos]
    @func_pos = self[:func_pos]
  end
  if self[:token_size]
    @token_size = self[:token_size]
  end
  if self[:token_pos]
    @token_pos = self[:token_pos]
  end
  if self[:score]
    @score = self[:score]
  end
  if self[:feature_list_size]
    @feature_list_size = self[:feature_list_size]
  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

      # create a new hash from @feature_list
      @features = Hash[*@feature_list.map {|f| f.split(':') }.flatten].freeze
    end
  end
end

Instance Attribute Details

#additional_infoObject (readonly)

Returns the value of attribute additional_info.



176
177
178
# File 'lib/nimono/cabocha_lib.rb', line 176

def additional_info
  @additional_info
end

#feature_listObject (readonly)

Returns the value of attribute feature_list.



175
176
177
# File 'lib/nimono/cabocha_lib.rb', line 175

def feature_list
  @feature_list
end

#feature_list_sizeObject (readonly)

Returns the value of attribute feature_list_size.



177
178
179
# File 'lib/nimono/cabocha_lib.rb', line 177

def feature_list_size
  @feature_list_size
end

#featuresObject (readonly)

:features is a hash of elements of :feature_list separated by colons.



180
181
182
# File 'lib/nimono/cabocha_lib.rb', line 180

def features
  @features
end

#func_posObject (readonly)

Returns the value of attribute func_pos.



171
172
173
# File 'lib/nimono/cabocha_lib.rb', line 171

def func_pos
  @func_pos
end

#head_posObject (readonly)

Returns the value of attribute head_pos.



170
171
172
# File 'lib/nimono/cabocha_lib.rb', line 170

def head_pos
  @head_pos
end

#idObject (readonly)

Returns the value of attribute id.



182
183
184
# File 'lib/nimono/cabocha_lib.rb', line 182

def id
  @id
end

Returns the value of attribute link.



169
170
171
# File 'lib/nimono/cabocha_lib.rb', line 169

def link
  @link
end

#scoreObject (readonly)

Returns the value of attribute score.



174
175
176
# File 'lib/nimono/cabocha_lib.rb', line 174

def score
  @score
end

#token_posObject (readonly)

Returns the value of attribute token_pos.



173
174
175
# File 'lib/nimono/cabocha_lib.rb', line 173

def token_pos
  @token_pos
end

#token_sizeObject (readonly)

Returns the value of attribute token_size.



172
173
174
# File 'lib/nimono/cabocha_lib.rb', line 172

def token_size
  @token_size
end

#tokensObject (readonly)

Returns the value of attribute tokens.



181
182
183
# File 'lib/nimono/cabocha_lib.rb', line 181

def tokens
  @tokens
end

Instance Method Details

#to_sObject



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

def to_s
  @to_s ||= tokens.map{|t| t.to_s}.join
end