line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# --*-Perl-*-- |
2
|
|
|
|
|
|
|
# $Id: BP.pm 25 2005-09-17 21:45:54Z tandler $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Biblio::BP - Package Frontend for bp (Perl Bibliography Package) |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Biblio::BP; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
well, I guess it\'s better if you check the source or the original docs |
16
|
|
|
|
|
|
|
for now .... sorry ... ;-) |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Biblio::BP; |
21
|
2
|
|
|
2
|
|
39
|
use 5.006; |
|
2
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
81
|
|
22
|
|
|
|
|
|
|
#no strict; # for strange AUTOLOAD method call ... |
23
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
24
|
|
|
|
|
|
|
#use English; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# for debug: |
27
|
2
|
|
|
2
|
|
8
|
use Data::Dumper; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
100
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
BEGIN { |
30
|
2
|
|
|
2
|
|
10
|
use vars qw($Revision $VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
198
|
|
31
|
2
|
50
|
|
2
|
|
6
|
my $major = 1; q$Revision: 25 $ =~ /: (\d+)/; my ($minor) = ($1); $VERSION = "$major." . ($minor<10 ? '0' : '') . $minor;
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
19
|
|
|
2
|
|
|
|
|
46
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# superclass |
35
|
|
|
|
|
|
|
#use YYYY; |
36
|
|
|
|
|
|
|
#use vars qw(@ISA); |
37
|
|
|
|
|
|
|
#@ISA = qw(YYYY); |
38
|
|
|
|
|
|
|
## now: use base YYYY |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# used modules |
41
|
2
|
|
|
2
|
|
890
|
use FileHandle;
|
|
2
|
|
|
|
|
11826
|
|
|
2
|
|
|
|
|
16
|
|
42
|
2
|
|
|
2
|
|
769
|
use File::Basename;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
143
|
|
43
|
2
|
|
|
2
|
|
14
|
use File::Spec; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# used own modules |
46
|
2
|
|
|
2
|
|
2263
|
use Biblio::Util; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
366
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# module variables |
49
|
|
|
|
|
|
|
#use vars qw(mmmm); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# |
53
|
|
|
|
|
|
|
# module initialization |
54
|
|
|
|
|
|
|
# |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
BEGIN {
|
57
|
2
|
50
|
|
2
|
|
12
|
if( defined $ENV{'BPHOME'} ) {
|
58
|
0
|
|
|
|
|
0
|
unshift(@INC, $ENV{'BPHOME'}); |
59
|
|
|
|
|
|
|
} else {
|
60
|
2
|
|
|
|
|
6
|
my $dir = $INC{'Biblio/BP.pm'};
|
61
|
2
|
50
|
|
|
|
12
|
die("Cannot find Biblio/BP.pm in %INC") unless $dir;
|
62
|
2
|
|
|
|
|
189
|
$dir = File::Spec->catdir(dirname($dir), 'bp', 'lib');
|
63
|
2
|
50
|
|
|
|
80
|
die("Cannot find the bp/lib directory of the Biblio::BP module in $dir")
|
64
|
|
|
|
|
|
|
unless -d $dir;
|
65
|
2
|
|
|
|
|
7
|
unshift @INC, $dir;
|
66
|
|
|
|
|
|
|
}
|
67
|
2
|
|
|
|
|
14916
|
require "bp.pl"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# set some useful defaults ... |
72
|
|
|
|
|
|
|
# automatically detect format: |
73
|
|
|
|
|
|
|
Biblio::BP::format("auto"); |
74
|
|
|
|
|
|
|
# print warnings, exit on errors: |
75
|
|
|
|
|
|
|
Biblio::BP::errors("print", "exit"); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 METHODS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# |
84
|
|
|
|
|
|
|
# |
85
|
|
|
|
|
|
|
# export to file |
86
|
|
|
|
|
|
|
# |
87
|
|
|
|
|
|
|
# the caller should set the output format before calling export. |
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item $no_items = export($outfile, $refs) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub export { |
95
|
0
|
|
|
0
|
1
|
0
|
my ($outfile, $refs) = @_; |
96
|
0
|
|
|
|
|
0
|
print STDERR 'exporting ', scalar(keys %$refs), " references\n"; |
97
|
0
|
0
|
|
|
|
0
|
if( ! Biblio::BP::open('>' . $outfile) ) { |
98
|
0
|
|
|
|
|
0
|
print STDERR "Could not open $outfile for writing\n"; |
99
|
0
|
|
|
|
|
0
|
return undef; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
#print Dumper $refs->{'CACM.CFW-LessonsLearned'}; |
102
|
0
|
|
|
|
|
0
|
foreach my $refID (keys(%$refs)) { |
103
|
0
|
|
|
|
|
0
|
my $ref = $refs->{$refID}; |
104
|
0
|
|
|
|
|
0
|
print STDERR "$refID - "; |
105
|
|
|
|
|
|
|
# print Dumper $ref; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# convert entries from pbib to bp's canon format |
108
|
0
|
|
|
|
|
0
|
my %can = Biblio::BP::pbib_to_canon(%{$ref}); |
|
0
|
|
|
|
|
0
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# convert from canon to output format and implode |
111
|
|
|
|
|
|
|
# to a single string replresentation |
112
|
0
|
|
|
|
|
0
|
my $record = Biblio::BP::implode(Biblio::BP::fromcanon(%can)); |
113
|
|
|
|
|
|
|
# print STDERR "$record\n"; |
114
|
0
|
|
|
|
|
0
|
Biblio::BP::write($outfile, $record); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
Biblio::BP::close('>' . $outfile); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
print STDERR "\ndone"; |
120
|
0
|
|
|
|
|
0
|
Biblio::BP::print_error_totals(); |
121
|
0
|
|
|
|
|
0
|
print STDERR "\n"; |
122
|
0
|
|
|
|
|
0
|
return scalar(keys %$refs); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
# import & convert from pbib to bp canon format |
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item $refs = import($args, @files) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$args = { |
135
|
|
|
|
|
|
|
-category => 'default-category', |
136
|
|
|
|
|
|
|
-citekey => 1 # create new canonical citekey |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub import { |
142
|
3
|
|
|
3
|
|
9
|
my ($args, @files) = @_; |
143
|
3
|
|
|
|
|
12
|
my $default_category = $args->{'-category'}; |
144
|
3
|
|
|
|
|
8
|
my $create_citekey = $args->{'-citekey'}; |
145
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
18
|
Biblio::BP::format("auto", "canon:8859-1"); |
147
|
3
|
|
|
|
|
19
|
my ($informat, $outformat) = Biblio::BP::format(); |
148
|
3
|
|
|
|
|
16
|
print STDERR "Using bp, version ", Biblio::BP::doc('version'), ".\n"; |
149
|
3
|
|
|
|
|
186
|
print STDERR "Reading: $informat Writing: $outformat\n"; |
150
|
3
|
50
|
|
|
|
15
|
print STDERR "Default category: $default_category\n" if $default_category; |
151
|
3
|
|
|
|
|
171
|
print STDERR "\n"; |
152
|
|
|
|
|
|
|
|
153
|
3
|
|
|
|
|
7
|
my ($fmt, $lastfmt); |
154
|
0
|
|
|
|
|
0
|
my ($ref, $rn, @refs); $rn=0; |
|
3
|
|
|
|
|
6
|
|
155
|
3
|
|
|
|
|
138
|
foreach my $file (@files) { |
156
|
0
|
|
|
|
|
0
|
print STDERR "Import $file ...\n"; |
157
|
0
|
|
|
|
|
0
|
$fmt = Biblio::BP::open($file); |
158
|
0
|
0
|
|
|
|
0
|
next unless defined $fmt; |
159
|
0
|
|
|
|
|
0
|
while ( defined($ref = Biblio::BP::readpbib(undef, undef, $default_category)) ) { |
160
|
0
|
|
|
|
|
0
|
$rn++; |
161
|
0
|
|
|
|
|
0
|
print $ref->{'CiteKey'}, "\n"; |
162
|
|
|
|
|
|
|
# print Dumper $ref; |
163
|
0
|
0
|
0
|
|
|
0
|
if( $create_citekey || $ref->{'CiteKey'} =~ /^\d+$/ ) { |
164
|
0
|
|
|
|
|
0
|
my $key = Biblio::Util::defaultCiteKey($ref, $create_citekey); |
165
|
0
|
|
|
|
|
0
|
print "-> $key\n"; |
166
|
0
|
|
|
|
|
0
|
$ref->{'CiteKey'} = $key; |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
0
|
push @refs, $ref; |
169
|
|
|
|
|
|
|
} |
170
|
0
|
|
|
|
|
0
|
print STDERR "$rn records read from $file"; |
171
|
0
|
|
|
|
|
0
|
Biblio::BP::print_error_totals(); |
172
|
0
|
|
|
|
|
0
|
print STDERR ".\n"; |
173
|
0
|
|
|
|
|
0
|
Biblio::BP::close(); |
174
|
0
|
|
|
|
|
0
|
return \@refs; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# |
183
|
|
|
|
|
|
|
# |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
our @nameFields = qw/ |
186
|
|
|
|
|
|
|
Authors |
187
|
|
|
|
|
|
|
Editors |
188
|
|
|
|
|
|
|
AuthorPseudonym |
189
|
|
|
|
|
|
|
/; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
### unused?? |
192
|
|
|
|
|
|
|
our %aliasFields = qw/ |
193
|
|
|
|
|
|
|
Author Authors |
194
|
|
|
|
|
|
|
Editor Editors |
195
|
|
|
|
|
|
|
/; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
### unused?? |
198
|
|
|
|
|
|
|
our %aliasCiteTypes = qw/ |
199
|
|
|
|
|
|
|
techreport report |
200
|
|
|
|
|
|
|
/; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
our %pbibFields = qw( |
204
|
|
|
|
|
|
|
bibdate BibDate |
205
|
|
|
|
|
|
|
bibsource BibSource |
206
|
|
|
|
|
|
|
bibnote BibNote |
207
|
|
|
|
|
|
|
category Category |
208
|
|
|
|
|
|
|
citealias CiteAliases |
209
|
|
|
|
|
|
|
citealiases CiteAliases |
210
|
|
|
|
|
|
|
crossref CrossRef
|
211
|
|
|
|
|
|
|
xref CrossRef |
212
|
|
|
|
|
|
|
origcitetype OrigCiteType |
213
|
|
|
|
|
|
|
pbibcitetype PBibCiteType |
214
|
|
|
|
|
|
|
identifier Identifier |
215
|
|
|
|
|
|
|
file File |
216
|
|
|
|
|
|
|
pbibnote PBibNote |
217
|
|
|
|
|
|
|
isbn ISBN |
218
|
|
|
|
|
|
|
issn ISSN |
219
|
|
|
|
|
|
|
url Source |
220
|
|
|
|
|
|
|
pdf PDF |
221
|
|
|
|
|
|
|
html HTML |
222
|
|
|
|
|
|
|
ps PS |
223
|
|
|
|
|
|
|
source SourceType |
224
|
|
|
|
|
|
|
recommendation Recommendation |
225
|
|
|
|
|
|
|
email AuthorEMail |
226
|
|
|
|
|
|
|
project Project |
227
|
|
|
|
|
|
|
subject Subject |
228
|
|
|
|
|
|
|
accessmonth AccessMonth |
229
|
|
|
|
|
|
|
accessyear AccessYear |
230
|
|
|
|
|
|
|
doi DOI |
231
|
|
|
|
|
|
|
abstract Abstract |
232
|
|
|
|
|
|
|
); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# "-" -> Range, i.e. can contain "--" etc. |
235
|
|
|
|
|
|
|
# "*" -> List, separated by "," or ";" |
236
|
|
|
|
|
|
|
### not yet used .... |
237
|
|
|
|
|
|
|
our %pbibFieldTypes = qw( |
238
|
|
|
|
|
|
|
AuthorEMail EMail* |
239
|
|
|
|
|
|
|
AuthorURL URL* |
240
|
|
|
|
|
|
|
Authors Name* |
241
|
|
|
|
|
|
|
BibDate Date |
242
|
|
|
|
|
|
|
BibSource URL* |
243
|
|
|
|
|
|
|
DOI URL |
244
|
|
|
|
|
|
|
Editors Name* |
245
|
|
|
|
|
|
|
Pages String-* |
246
|
|
|
|
|
|
|
PDF URL* |
247
|
|
|
|
|
|
|
Source URL* |
248
|
|
|
|
|
|
|
); |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item $rec = readpbib($file, $format, $default_category) |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
read a record from the current bp input file (via BP::read()) and |
253
|
|
|
|
|
|
|
convert it to a pbib compliant paper hash reference |
254
|
|
|
|
|
|
|
(or undef for EOF) |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=cut |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub readpbib { |
259
|
134
|
|
|
134
|
1
|
206
|
my ($file, $format, $default_category) = @_; |
260
|
134
|
|
|
|
|
154
|
my ($record, $rn, %rec); |
261
|
134
|
50
|
|
|
|
377
|
$file = $bib'glb_Ifilename unless defined $file; |
262
|
134
|
|
|
|
|
466
|
$record = Biblio::BP::read(@_); |
263
|
134
|
100
|
|
|
|
381
|
unless( defined $record ) { return undef; } |
|
2
|
|
|
|
|
12
|
|
264
|
|
|
|
|
|
|
|
265
|
132
|
|
|
|
|
199
|
chop $record; |
266
|
132
|
|
|
|
|
448
|
%rec = Biblio::BP::explode($record); |
267
|
132
|
|
|
|
|
1009
|
%rec = Biblio::BP::tocanon(%rec); |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# print $rec{'CiteKey'}, "\n"; |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# convert Authors field etc. from canon to pbib format |
272
|
132
|
|
|
|
|
1087
|
%rec = Biblio::BP::canon_to_pbib(%rec); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# ... BibDate/BibSource field |
275
|
132
|
100
|
|
|
|
785
|
if( ! defined $rec{'BibDate'} ) { |
276
|
8
|
|
|
|
|
660
|
$rec{'BibDate'} = localtime(); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
# if( ! defined $rec{'BibSource'} ) { |
279
|
|
|
|
|
|
|
# $rec{'BibSource'} = $file; |
280
|
|
|
|
|
|
|
# } |
281
|
|
|
|
|
|
|
# ... Category field |
282
|
132
|
50
|
33
|
|
|
470
|
if( ! defined $rec{'Category'} && defined $default_category) { |
283
|
0
|
|
|
|
|
0
|
$rec{'Category'} = $default_category; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
#### ??? |
287
|
132
|
50
|
|
|
|
277
|
if( defined $ref{'PBibNote'} ) { |
288
|
0
|
|
|
|
|
0
|
delete $ref{'PBibNote'}; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# ... remove abstract ... |
292
|
132
|
50
|
|
|
|
263
|
if( defined $rec{'Abstract'} ) { |
293
|
|
|
|
|
|
|
# it's simply too long for my stupid databse ... |
294
|
0
|
|
|
|
|
0
|
delete $rec{'Abstract'}; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
132
|
|
|
|
|
641
|
return \%rec; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
my %pbib_to_canon_types = qw( |
302
|
|
|
|
|
|
|
booklet book |
303
|
|
|
|
|
|
|
collection book |
304
|
|
|
|
|
|
|
conference inproceedings |
305
|
|
|
|
|
|
|
incollection inbook |
306
|
|
|
|
|
|
|
journal article |
307
|
|
|
|
|
|
|
masterthesis thesis |
308
|
|
|
|
|
|
|
phdthesis thesis |
309
|
|
|
|
|
|
|
techreport report |
310
|
|
|
|
|
|
|
email misc |
311
|
|
|
|
|
|
|
video misc |
312
|
|
|
|
|
|
|
speech misc |
313
|
|
|
|
|
|
|
talk inproceedings |
314
|
|
|
|
|
|
|
poster inproceedings |
315
|
|
|
|
|
|
|
patent misc |
316
|
|
|
|
|
|
|
avmaterial misc |
317
|
|
|
|
|
|
|
web misc |
318
|
|
|
|
|
|
|
); |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=item %rec = pbib_to_canon(%rec) |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Convert pbib record to bp's canon format |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=cut |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
sub pbib_to_canon { |
327
|
0
|
|
|
0
|
1
|
0
|
my (%rec) = @_; |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# Institution --> Organization |
330
|
0
|
0
|
0
|
|
|
0
|
if( $rec{'Institution'} && ! $rec{'Organization'} ) { |
331
|
0
|
|
|
|
|
0
|
$rec{'Organization'} = $rec{'Institution'}; |
332
|
0
|
|
|
|
|
0
|
delete $rec{'Institution'}; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
# convert names |
336
|
0
|
|
|
|
|
0
|
foreach my $f (@nameFields) { |
337
|
0
|
0
|
|
|
|
0
|
next unless $rec{$f}; |
338
|
0
|
|
|
|
|
0
|
$rec{$f} = Biblio::BP::Util::mname_to_canon($rec{$f}); |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
### convert new CiteTypes: |
342
|
|
|
|
|
|
|
### patent, phdthesis, masterthesis, incollection, web, techreport, ... |
343
|
0
|
|
|
|
|
0
|
my $CiteType = $rec{'CiteType'}; |
344
|
0
|
0
|
|
|
|
0
|
if( defined $CiteType ) { |
345
|
0
|
0
|
|
|
|
0
|
if( defined $pbib_to_canon_types{$CiteType} ) { |
346
|
|
|
|
|
|
|
# unsupported bp type |
347
|
0
|
|
|
|
|
0
|
$rec{'PBibCiteType'} = $CiteType; |
348
|
0
|
|
|
|
|
0
|
$rec{'CiteType'} = $pbib_to_canon_types{$CiteType}; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# adapt fields for techreport |
352
|
0
|
0
|
0
|
|
|
0
|
if( $CiteType =~ /report$/ && ! defined $rec{'ReportNumber'} ) { |
353
|
0
|
|
|
|
|
0
|
$rec{'ReportNumber'} = $rec{'Number'}; |
354
|
0
|
|
|
|
|
0
|
delete $rec{'Number'}; |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# adapt fields for thesis |
358
|
0
|
0
|
0
|
|
|
0
|
if( $CiteType eq 'phdthesis' && ! defined $rec{'ReportType'} ) { |
359
|
0
|
|
|
|
|
0
|
$rec{'ReportType'} = 'Ph.D. thesis'; |
360
|
|
|
|
|
|
|
} |
361
|
0
|
0
|
0
|
|
|
0
|
if( $CiteType eq 'masterthesis' && ! defined $rec{'ReportType'} ) { |
362
|
0
|
|
|
|
|
0
|
$rec{'ReportType'} = 'masterthesis'; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
} else { |
365
|
0
|
|
|
|
|
0
|
$rec{'CiteType'} = 'inproceedings'; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
0
|
|
|
|
|
0
|
return %rec; |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=item %rec = canon_to_pbib(%rec) |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
Convert record in bp's canon format to pbib's format. |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
=cut |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
sub canon_to_pbib { |
378
|
132
|
|
|
132
|
1
|
656
|
my (%rec) = @_; |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# ... lower case field names |
381
|
132
|
|
|
|
|
665
|
foreach my $f (keys %pbibFields) { |
382
|
3696
|
100
|
66
|
|
|
8731
|
if( defined $rec{$f} && ! defined $rec{$pbibFields{$f}} ) { |
383
|
588
|
|
|
|
|
1104
|
$rec{$pbibFields{$f}} = $rec{$f}; |
384
|
588
|
|
|
|
|
889
|
delete $rec{$f}; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
# ... Name format |
389
|
|
|
|
|
|
|
##### ToDo: check, if the pbib quoted format needs to be used |
390
|
|
|
|
|
|
|
##### e.g. /Da Campo/Sandra/ |
391
|
132
|
|
|
|
|
431
|
foreach my $f (@nameFields) { |
392
|
396
|
100
|
|
|
|
965
|
next unless $rec{$f}; |
393
|
120
|
|
|
|
|
536
|
$rec{$f} = Biblio::BP::Util::canon_to_name($rec{$f}, 'plain'); |
394
|
|
|
|
|
|
|
#print "\n$f = $rec{$f}\n\n"; |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
# ... char set & bp's meta stuff |
398
|
|
|
|
|
|
|
# foreach my $f (keys(%rec)) { |
399
|
|
|
|
|
|
|
# hm. |
400
|
|
|
|
|
|
|
# }
|
401
|
132
|
|
|
|
|
427
|
Biblio::BP::format("canon:canon", "canon:utf8"); |
402
|
132
|
|
|
|
|
869
|
%rec = Biblio::BP::fromcanon(%rec); # e.g. to convert the charset |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
# ... CiteType |
405
|
132
|
50
|
66
|
|
|
1138
|
if( ! defined $rec{'PBibCiteType'} && defined $rec{'OrigCiteType'} ) { |
406
|
0
|
|
|
|
|
0
|
$rec{'PBibCiteType'} = $rec{'OrigCiteType'}; |
407
|
0
|
|
|
|
|
0
|
delete $rec{'OrigCiteType'}; |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
###### ToDo: check for "OrigCiteType" field & adapt CiteType |
410
|
132
|
100
|
|
|
|
307
|
if( defined $rec{'PBibCiteType'} ) { |
411
|
20
|
|
|
|
|
40
|
$rec{'CiteType'} = $rec{'PBibCiteType'}; |
412
|
20
|
|
|
|
|
40
|
delete $rec{'PBibCiteType'}; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
### temp only!!!! |
416
|
|
|
|
|
|
|
###### --> move to Biblio::Database! |
417
|
132
|
100
|
|
|
|
284
|
if( defined($rec{'PBibNote'}) ) { |
418
|
40
|
|
|
|
|
149
|
my @fields = split(/\r?\n/, $rec{'PBibNote'}); |
419
|
|
|
|
|
|
|
#print STDERR $rec{'CiteKey'}, $rec{'PBibNote'}, "\n"; |
420
|
|
|
|
|
|
|
#my $dump =0; |
421
|
40
|
|
|
|
|
53
|
my @notes; |
422
|
40
|
|
|
|
|
94
|
foreach my $f (@fields) { |
423
|
40
|
50
|
|
|
|
113
|
if( $f =~ /^([a-z]+)=\s*(.*)\s*$/i ) { |
424
|
0
|
|
|
|
|
0
|
$rec{$1} = $2; #$dump = 1; |
425
|
|
|
|
|
|
|
} else { |
426
|
40
|
|
|
|
|
107
|
push @notes, $f; |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
} |
429
|
40
|
50
|
|
|
|
92
|
if( @notes ) { |
430
|
40
|
|
|
|
|
134
|
$rec{'PBibNote'} = join("\n", @notes); |
431
|
|
|
|
|
|
|
} else { |
432
|
0
|
|
|
|
|
0
|
delete $rec{'PBibNote'}; |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
#print Dumper \%rec if $dump; |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
132
|
|
|
|
|
1731
|
return %rec; |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=back |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
=cut |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
# |
445
|
|
|
|
|
|
|
# |
446
|
|
|
|
|
|
|
# some additional helper functions |
447
|
|
|
|
|
|
|
# |
448
|
|
|
|
|
|
|
# |
449
|
|
|
|
|
|
|
#### --> maybe move this to Biblio.pm or (better?) directly to bp.pl ....! |
450
|
|
|
|
|
|
|
# |
451
|
|
|
|
|
|
|
# |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
sub querySupportedFormats { |
455
|
0
|
|
|
0
|
0
|
0
|
my ($fmts, $csets) = bib::find_bp_files(); |
456
|
0
|
|
|
|
|
0
|
return split(/\s+/, $fmts); |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
sub querySupportedCharsets { |
460
|
0
|
|
|
0
|
0
|
0
|
my ($fmts, $csets) = bib::find_bp_files(); |
461
|
0
|
|
|
|
|
0
|
return split(/\s+/, $csets); |
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
our ($logfilename, $loglevel, $logfilehandle); |
468
|
|
|
|
|
|
|
$loglevel = $bib::opt_default_debug_level; |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
sub logfilename { |
471
|
0
|
0
|
|
0
|
0
|
0
|
if( @_ ) { |
472
|
0
|
|
|
|
|
0
|
$logfilename = $_[0]; |
473
|
0
|
|
|
|
|
0
|
$logfilehandle = undef; |
474
|
0
|
0
|
|
|
|
0
|
$loglevel = $_[1] if defined($_[1]); |
475
|
|
|
|
|
|
|
} |
476
|
0
|
|
|
|
|
0
|
return $logfilename; |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
sub logs { |
479
|
0
|
|
|
0
|
0
|
0
|
print STDERR @_, '\n'; |
480
|
0
|
0
|
|
|
|
0
|
return unless defined($logfilename); |
481
|
|
|
|
|
|
|
# open logfile |
482
|
0
|
0
|
|
|
|
0
|
unless( defined($logfilehandle) ) { |
483
|
0
|
0
|
|
|
|
0
|
$logfilehandle = new FileHandle(">$logfilename") |
484
|
|
|
|
|
|
|
or Biblio::BP::goterror("Can't open logfile $logfilename for writing"); |
485
|
|
|
|
|
|
|
} |
486
|
0
|
|
|
|
|
0
|
print $logfilehandle @_, '\n'; |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub debugs { |
490
|
0
|
|
|
0
|
0
|
0
|
my ($statement, $level, $mod) = @_; |
491
|
0
|
0
|
0
|
|
|
0
|
if( defined($level) && $loglevel ) { |
492
|
0
|
0
|
0
|
|
|
0
|
if( $loglevel == 1 || $level > $loglevel ) { |
493
|
0
|
|
|
|
|
0
|
logs($statement); |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
} |
496
|
0
|
|
|
|
|
0
|
return bib::debugs($statement, $level, $mod); |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub goterror { |
500
|
0
|
|
|
0
|
0
|
0
|
my($error, $linenum) = @_; |
501
|
0
|
|
|
|
|
0
|
logs("error: $error"); |
502
|
0
|
|
|
|
|
0
|
return bib::goterror($error, $linenum); |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
sub gotwarn { |
506
|
0
|
|
|
0
|
0
|
0
|
my($warn, $linenum) = @_; |
507
|
0
|
|
|
|
|
0
|
logs("warning: warn"); |
508
|
0
|
|
|
|
|
0
|
return bib::gotwarn($warn, $linenum); |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
sub print_error_totals { |
512
|
0
|
|
|
0
|
0
|
0
|
my ($w, $e) = Biblio::BP::errors('totals'); |
513
|
0
|
0
|
|
|
|
0
|
$w && print STDERR (($w == 1) ? " (1 warning)" : " ($w warnings)"); |
|
|
0
|
|
|
|
|
|
514
|
0
|
0
|
|
|
|
0
|
$e && print STDERR (($e == 1) ? " (1 error)" : " ($e errors)"); |
|
|
0
|
|
|
|
|
|
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
# |
518
|
|
|
|
|
|
|
# |
519
|
|
|
|
|
|
|
# bp methods |
520
|
|
|
|
|
|
|
# |
521
|
|
|
|
|
|
|
# |
522
|
|
|
|
|
|
|
|
523
|
2
|
|
|
2
|
|
27
|
use vars qw($AUTOLOAD); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
301
|
|
524
|
|
|
|
|
|
|
sub AUTOLOAD { |
525
|
|
|
|
|
|
|
# my $self = shift; |
526
|
681
|
|
|
681
|
|
997
|
my ($method) = $AUTOLOAD; |
527
|
681
|
|
|
|
|
2003
|
my (@parameters) = @_; |
528
|
681
|
|
|
|
|
3757
|
$method =~ s/.*:://; |
529
|
681
|
|
|
|
|
1223
|
$method = "bib'$method"; |
530
|
681
|
|
|
|
|
2201
|
&bib'debugs("call method $method", 2); |
531
|
|
|
|
|
|
|
#print "self = $self call <$method> args: <@parameters>\n"; |
532
|
681
|
|
|
|
|
2809
|
&$method(@parameters); |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
package Biblio::BP::Util; |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
# |
539
|
|
|
|
|
|
|
# |
540
|
|
|
|
|
|
|
# bp_util methods |
541
|
|
|
|
|
|
|
# |
542
|
|
|
|
|
|
|
# |
543
|
|
|
|
|
|
|
|
544
|
2
|
|
|
2
|
|
10
|
use vars qw($AUTOLOAD); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
306
|
|
545
|
|
|
|
|
|
|
sub AUTOLOAD { |
546
|
120
|
|
|
120
|
|
177
|
my ($method) = $AUTOLOAD; |
547
|
120
|
|
|
|
|
925
|
my (@parameters) = @_; |
548
|
120
|
|
|
|
|
508
|
$method =~ s/^.*:://; |
549
|
120
|
|
|
|
|
203
|
$method = "bp_util'$method"; |
550
|
120
|
|
|
|
|
402
|
&bib'debugs("call method $method", 2); |
551
|
|
|
|
|
|
|
#print "call <$method> args: <@parameters>\n"; |
552
|
120
|
|
|
|
|
525
|
&$method(@parameters); |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
1; |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
__END__ |