| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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
|
|
|
1
|
|
8
|
use DiaColloDB::Logger; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
347
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
##============================================================================== |
|
11
|
|
|
|
|
|
|
## Globals & Constants |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
|
31
|
0
|
|
|
0
|
1
|
|
my $that = shift; |
|
32
|
0
|
|
0
|
|
|
|
my $doc = bless({ |
|
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
|
|
|
|
|
|
|
sub fromFile { |
|
49
|
0
|
|
|
0
|
1
|
|
my ($doc,$file) = @_; |
|
50
|
0
|
|
|
|
|
|
$doc->logconfess("fromFile() not implemented for '$file': $!"); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## $label = $doc->label() |
|
54
|
|
|
|
|
|
|
sub label { |
|
55
|
0
|
|
0
|
0
|
1
|
|
return $_[0]{label} // "$_[0]"; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
## $ext = $doc->extension() |
|
59
|
|
|
|
|
|
|
## + default extension (including dot), for Corpus::Compiled |
|
60
|
|
|
|
|
|
|
sub extension { |
|
61
|
0
|
|
|
0
|
0
|
|
return ''; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
##============================================================================== |
|
65
|
|
|
|
|
|
|
## Storable hooks |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
## ($serialized, $ref1, ...) = $obj->STORABLE_freeze($cloning) |
|
68
|
|
|
|
|
|
|
sub STORABLE_freeze { |
|
69
|
0
|
|
|
0
|
0
|
|
my ($obj,$cloning) = @_; |
|
70
|
0
|
|
|
|
|
|
my $ref = {}; |
|
71
|
0
|
|
|
|
|
|
foreach (keys %$obj) { |
|
72
|
0
|
0
|
|
|
|
|
$ref->{$_} = (UNIVERSAL::isa($obj->{$_},'Regexp') ? "$obj->{$_}" : $obj->{$_}); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
|
|
|
|
|
return ('',$ref); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
## $obj = STORABLE_thaw($obj, $cloning, $serialized, $ref1,...) |
|
78
|
|
|
|
|
|
|
sub STORABLE_thaw { |
|
79
|
0
|
|
|
0
|
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; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|