NAME
Slob - Read .slob dictionaries (as used by Aard 2)
SYNOPSIS
use feature qw/:5.14/;
use Slob;
my $slob = Slob->new('path/to/dict.slob');
my $nr_of_entries = $slob->ref_count; # if the same content has two
# keys pointing to it, this
# counts it twice
my $second_ref = $slob->seek_and_read_ref(4);
say "Entry is for $second_ref->{key}";
say "Data is in bin $second_ref->{bin_index} at position $second_ref->{item_index}";
my $bin = $slob->seek_and_read_storage_bin($second_ref->{bin_index});
say "Bin has ", (scalar @{$bin->{positions}}), " entries";
say "Value at position $second_ref->{item_index} is ",
$slob->get_entry_of_storage_bin($bin, $second_ref->{item_index});
# instead of the above, we can do
my $second_ref_and_data = $slob->seek_and_read_ref_and_data(4);
say "Entry is for $second_ref_and_data->{key}";
say "Value is $second_ref_and_data->{data}";
DESCRIPTION
Slob is a compressed read-only format for storing natural language dictionaries. It is used in Aard 2. Slob.pm
is a module that reads dictionaries in slob format.
The following methods are available:
- Slob->new($path) =item Slob->new($fh)
-
Create a new slob reader reading from the given path or filehandle.
- $slob->ref_count
-
The number of refs (keys) in the dictionary.
- $slob->seek_and_read_ref($index)
-
Read the ref (key) at the given index. Returns a hashref with the following keys:
- key
-
The key
- bin_index
-
The storage bin that contains the value for this key
- item_index
-
The index in the bin_index storage bin of the value for this key
- fragment
-
HTML fragment that, when applied to the HTML value, points to the definition of the key.
- $slob->seek_and_read_storage_bin($index)
-
Read the storage bin with the given index. Returns the storage bin, which can later be given to get_entry_of_storage_bin.
- $slob->get_entry_of_storage_bin($bin, $index)
-
Given a storage bin (as returned by
seek_and_read_storage_bin
) and item index, returns the value at the index i nthe storage bin. - $slob->seek_and_read_ref_and_data($index)
-
Convenience method that returns the key and value at a given index. Returns a hashref like
seek_and_read_ref
with an extra key, data, which is the value of the key.
SEE ALSO
https://github.com/itkach/slob
AUTHOR
Marius Gavrilescu, <marius@ieval.ro>
COPYRIGHT AND LICENSE
Copyright (C) 2017 by Marius Gavrilescu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.26.1 or, at your option, any later version of Perl 5 you may have available.