Class: BlingFire::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/blingfire/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(path = nil, prefix: nil) ⇒ Model

Returns a new instance of Model.



3
4
5
6
7
8
9
10
11
12
13
14
# 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)
    @handle.free = FFI["FreeModel"]

    BlingFire.change_settings_dummy_prefix(@handle, prefix) unless prefix.nil?
  else
    raise Error, "prefix option requires path" unless prefix.nil?
  end
end

Instance Method Details

#ids_to_text(ids, skip_special_tokens: true, output_buffer_size: nil) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/blingfire/model.rb', line 64

def ids_to_text(ids, skip_special_tokens: true, output_buffer_size: nil)
  if @handle
    BlingFire.ids_to_text(@handle, ids, skip_special_tokens: skip_special_tokens, output_buffer_size: output_buffer_size)
  else
    raise "Not implemented"
  end
end

#text_to_ids(text, max_len = nil, unk_id = 0) ⇒ Object



48
49
50
51
52
53
54
# 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) ⇒ Object



56
57
58
59
60
61
62
# 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) ⇒ Object



32
33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
43
44
45
46
# 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) ⇒ Object



16
17
18
19
20
21
22
# 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) ⇒ Object



24
25
26
27
28
29
30
# 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_ptrObject



72
73
74
# File 'lib/blingfire/model.rb', line 72

def to_ptr
  @handle
end