Class: VinaryTree::Libdictenstein::PersistentVocabulary
- Inherits:
-
Dictionary
- Object
- Dictionary
- VinaryTree::Libdictenstein::PersistentVocabulary
show all
- Defined in:
- lib/vinary_tree/libdictenstein.rb
Instance Attribute Summary
Attributes inherited from Dictionary
#handle
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Dictionary
#capabilities, #close, #each, #entries, #entry_stream, finalizer, #get, #get_u64, #include?, #include_u64?, #initialize, #keys, #kind, #length, #values, #with_resource
Class Method Details
.create(path) ⇒ Object
456
|
# File 'lib/vinary_tree/libdictenstein.rb', line 456
def self.create(path) = open_native(path, true)
|
.open(path) ⇒ Object
457
|
# File 'lib/vinary_tree/libdictenstein.rb', line 457
def self.open(path) = open_native(path, false)
|
.open_native(path, create) ⇒ Object
458
459
460
461
462
|
# File 'lib/vinary_tree/libdictenstein.rb', line 458
def self.open_native(path, create)
text = File.expand_path(path).b; output = Native.pointer_output
function = create ? :ldict_persistent_vocab_create : :ldict_persistent_vocab_open
Libdictenstein.check(Native.public_send(function, text, text.bytesize, output)); new(Native.read_pointer(output))
end
|
Instance Method Details
#checkpoint ⇒ Object
472
|
# File 'lib/vinary_tree/libdictenstein.rb', line 472
def checkpoint = @handle.with_pointer { |pointer| Libdictenstein.check(Native.ldict_dictionary_checkpoint(pointer)) }
|
#put(term, index) ⇒ Object
463
|
# File 'lib/vinary_tree/libdictenstein.rb', line 463
def put(term, index) = put_text(term, index)
|
#term(index) ⇒ Object
464
465
466
467
468
469
470
471
|
# File 'lib/vinary_tree/libdictenstein.rb', line 464
def term(index)
length, found = Native.size_output, Native.byte_output
@handle.with_pointer { |pointer| Libdictenstein.check(Native.ldict_vocab_get_term(pointer, index, 0, 0, length, found)) }
return nil if found[0].zero?
output = Fiddle::Pointer.malloc(Native.read_size(length), Fiddle::RUBY_FREE)
@handle.with_pointer { |pointer| Libdictenstein.check(Native.ldict_vocab_get_term(pointer, index, output, output.size, length, found)) }
output[0, Native.read_size(length)].force_encoding(Encoding::UTF_8)
end
|