| 1 | ## -*- Mode: CPerl -*- | ||||||||||
| 2 | ## File: DiaColloDB::Document::Storable.pm | ||||||||||
| 3 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||
| 4 | ## Description: collocation db, source document, Storable (nstore_fd) | ||||||||||
| 5 | |||||||||||
| 6 | package DiaColloDB::Document::Storable; | ||||||||||
| 7 | 1 | ▶ | use DiaColloDB::Document; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Storable; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | ##============================================================================== | ||||||||||
| 12 | ## Globals & Constants | ||||||||||
| 13 | |||||||||||
| 14 | 1 | our @ISA = qw(DiaColloDB::Document); | |||||||||
| 15 | |||||||||||
| 16 | ##============================================================================== | ||||||||||
| 17 | ## Constructors etc. | ||||||||||
| 18 | |||||||||||
| 19 | ## $doc = CLASS_OR_OBJECT->new(%args) | ||||||||||
| 20 | ## + %args, object structure: | ||||||||||
| 21 | ## ( | ||||||||||
| 22 | ## ##-- document data | ||||||||||
| 23 | ## date =>$date, ##-- year | ||||||||||
| 24 | ## tokens =>\@tokens, ##-- tokens, including undef for EOS | ||||||||||
| 25 | ## meta =>\%meta, ##-- document metadata (e.g. author, title, collection, ...) | ||||||||||
| 26 | ## ) | ||||||||||
| 27 | ## + each token in @tokens is a HASH-ref {w=>$word,p=>$pos,l=>$lemma,...} | ||||||||||
| 28 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 29 | 0 | my $that = shift; | |||||||||
| 30 | 0 | my $doc = $that->SUPER::new( | |||||||||
| 31 | @_, ##-- user arguments | ||||||||||
| 32 | ); | ||||||||||
| 33 | 0 | return $doc; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | ##============================================================================== | ||||||||||
| 37 | ## API: I/O | ||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | ## $ext = $doc->extension() | ||||||||||
| 41 | ## + default extension, for Corpus::Compiled | ||||||||||
| 42 | 0 | ▶ | sub extension { | ||||||||
|
Subroutine
extension: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 43 | 0 | return '.sto'; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | ##-------------------------------------------------------------- | ||||||||||
| 47 | ## API: I/O: parse | ||||||||||
| 48 | |||||||||||
| 49 | ## $bool = $doc->fromFile($filename_or_fh, %opts) | ||||||||||
| 50 | ## + parse tokens from $filename_or_fh | ||||||||||
| 51 | ## + %opts : clobbers %$doc | ||||||||||
| 52 | 0 | ▶ | sub fromFile { | ||||||||
|
Subroutine
fromFile: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 53 | 0 | my ($doc,$file,%opts) = @_; | |||||||||
| 54 | 0 | ▶ | $doc = $doc->new() if (!ref($doc)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | @$doc{keys %opts} = values %opts; | |||||||||
| 56 | 0 | ▶ | $doc->{label} = ref($file) ? "$file" : $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | ▶ | my $ref = (ref($file) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | ? Storable::fd_retrieve($file) | ||||||||||
| 59 | : Storable::retrieve($file)); | ||||||||||
| 60 | 0 | ▶ | $doc->logconfess("fromFile(): failed to load Storable object from '$file'") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | if (!UNIVERSAL::isa($ref,'HASH')); | ||||||||||
| 62 | 0 | @$doc{keys %$ref} = values %$ref; | |||||||||
| 63 | 0 | return $doc; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | ##============================================================================== | ||||||||||
| 67 | ## Footer | ||||||||||
| 68 | 1 | 1; | |||||||||
| 69 | |||||||||||
| 70 | __END__ | ||||||||||