class BlingFire::Model
Public Class Methods
finalize(pointer)
click to toggle source
# File lib/blingfire/model.rb, line 68 def self.finalize(pointer) # must use proc instead of stabby lambda proc { FFI.FreeModel(pointer) } end
new(path = nil, prefix: nil)
click to toggle source
# File lib/blingfire/model.rb, line 3 def initialize(path = nil, prefix: nil) @handle = nil if path raise Error, "Model not found" unless File.exist?(path) @handle = FFI.LoadModel(path) ObjectSpace.define_finalizer(self, self.class.finalize(@handle)) BlingFire.change_settings_dummy_prefix(@handle, prefix) unless prefix.nil? else raise Error, "prefix option requires path" unless prefix.nil? end end
Public Instance Methods
text_to_ids(text, max_len = nil, unk_id = 0)
click to toggle source
# File lib/blingfire/model.rb, line 48 def text_to_ids(text, max_len = nil, unk_id = 0) if @handle BlingFire.text_to_ids(@handle, text, max_len, unk_id) else raise "Not implemented" end end
text_to_ids_with_offsets(text, max_len = nil, unk_id = 0)
click to toggle source
# File lib/blingfire/model.rb, line 56 def text_to_ids_with_offsets(text, max_len = nil, unk_id = 0) if @handle BlingFire.text_to_ids_with_offsets(@handle, text, max_len, unk_id) else raise "Not implemented" end end
text_to_sentences(text)
click to toggle source
# File lib/blingfire/model.rb, line 32 def text_to_sentences(text) if @handle BlingFire.text_to_sentences_with_model(@handle, text) else BlingFire.text_to_sentences(text) end end
text_to_sentences_with_offsets(text)
click to toggle source
# File lib/blingfire/model.rb, line 40 def text_to_sentences_with_offsets(text) if @handle BlingFire.text_to_sentences_with_offsets_with_model(@handle, text) else BlingFire.text_to_sentences_with_offsets(text) end end
text_to_words(text)
click to toggle source
# File lib/blingfire/model.rb, line 16 def text_to_words(text) if @handle BlingFire.text_to_words_with_model(@handle, text) else BlingFire.text_to_words(text) end end
text_to_words_with_offsets(text)
click to toggle source
# File lib/blingfire/model.rb, line 24 def text_to_words_with_offsets(text) if @handle BlingFire.text_to_words_with_offsets_with_model(@handle, text) else BlingFire.text_to_words_with_offsets(text) end end
to_ptr()
click to toggle source
# File lib/blingfire/model.rb, line 64 def to_ptr @handle end