| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||
| 2 | ## File: DiaColloDB::Document.pm | ||||||||||||||||||||
| 3 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||
| 4 | ## Description: collocation db, source document | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | package DiaColloDB::Document; | ||||||||||||||||||||
| 7 | 1 | ▶ | use DiaColloDB::Logger; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | ##============================================================================== | ||||||||||||||||||||
| 11 | ## Globals & Constants | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | our @ISA = qw(DiaColloDB::Logger); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | ##============================================================================== | ||||||||||||||||||||
| 16 | ## Constructors etc. | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | ## $doc = CLASS_OR_OBJECT->new(%args) | ||||||||||||||||||||
| 19 | ## + %args, object structure: | ||||||||||||||||||||
| 20 | ## ( | ||||||||||||||||||||
| 21 | ## label => $label, ##-- document label (e.g. filename; optional) | ||||||||||||||||||||
| 22 | ## date =>$date, ##-- year | ||||||||||||||||||||
| 23 | ## tokens =>\@tokens, ##-- tokens, including undef for eos | ||||||||||||||||||||
| 24 | ## meta =>\%meta, ##-- document metadata (e.g. author, title, collection, ...) | ||||||||||||||||||||
| 25 | ## ) | ||||||||||||||||||||
| 26 | ## + each token in @tokens is one of the following: | ||||||||||||||||||||
| 27 | ## - undef : EOS (default, for collocation profiling) | ||||||||||||||||||||
| 28 | ## - a HASH-ref : normal token: {w=>$word,p=>$pos,l=>$lemma,...} | ||||||||||||||||||||
| 29 | ## - a string : block boundary / "break", e.g. "s": sentence-break, "p": paragraph-break, ... | ||||||||||||||||||||
| 30 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 31 | 0 | my $that = shift; | |||||||||||||||||||
| 32 | 0 | ▶ | my $doc = bless({ | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 33 | label =>undef, | ||||||||||||||||||||
| 34 | date =>0, | ||||||||||||||||||||
| 35 | tokens=>[], | ||||||||||||||||||||
| 36 | meta =>{}, | ||||||||||||||||||||
| 37 | @_, ##-- user arguments | ||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||
| 39 | ref($that)||$that); | ||||||||||||||||||||
| 40 | 0 | return $doc; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | ##============================================================================== | ||||||||||||||||||||
| 44 | ## API: I/O | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | ## $bool = $doc->fromFile($filename_or_fh) | ||||||||||||||||||||
| 47 | ## + parse tokens from $filename_or_fh | ||||||||||||||||||||
| 48 | 0 | ▶ | sub fromFile { | ||||||||||||||||||
|
Subroutine
fromFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | my ($doc,$file) = @_; | |||||||||||||||||||
| 50 | 0 | $doc->logconfess("fromFile() not implemented for '$file': $!"); | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | ## $label = $doc->label() | ||||||||||||||||||||
| 54 | 0 | ▶ | sub label { | ||||||||||||||||||
|
Subroutine
label: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 55 | 0 | ▶ | return $_[0]{label} // "$_[0]"; | ||||||||||||||||||
|
Condition0%0/2
$_[0]{"label"} // "$_[0]"
MC/DC0%0/1
$_[0]{"label"} // "$_[0]"
$_[0]{"label"}
Truth table0%0/2
A
A= $_[0]{"label"}
| |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | ## $ext = $doc->extension() | ||||||||||||||||||||
| 59 | ## + default extension (including dot), for Corpus::Compiled | ||||||||||||||||||||
| 60 | 0 | ▶ | sub extension { | ||||||||||||||||||
|
Subroutine
extension: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | 0 | return ''; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | ##============================================================================== | ||||||||||||||||||||
| 65 | ## Storable hooks | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | ## ($serialized, $ref1, ...) = $obj->STORABLE_freeze($cloning) | ||||||||||||||||||||
| 68 | 0 | ▶ | sub STORABLE_freeze { | ||||||||||||||||||
|
Subroutine
STORABLE_freeze: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 69 | 0 | my ($obj,$cloning) = @_; | |||||||||||||||||||
| 70 | 0 | my $ref = {}; | |||||||||||||||||||
| 71 | 0 | foreach (keys %$obj) { | |||||||||||||||||||
| 72 | 0 | ▶ | $ref->{$_} = (UNIVERSAL::isa($obj->{$_},'Regexp') ? "$obj->{$_}" : $obj->{$_}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | return ('',$ref); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | ## $obj = STORABLE_thaw($obj, $cloning, $serialized, $ref1,...) | ||||||||||||||||||||
| 78 | 0 | ▶ | sub STORABLE_thaw { | ||||||||||||||||||
|
Subroutine
STORABLE_thaw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 79 | 0 | my ($obj,$cloning,$ser,$ref) = @_; | |||||||||||||||||||
| 80 | 0 | @$obj{keys %$ref} = values %$ref; | |||||||||||||||||||
| 81 | 0 | return $obj; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | ##============================================================================== | ||||||||||||||||||||
| 86 | ## Footer | ||||||||||||||||||||
| 87 | 1 | 1; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||