Debian Codegraph @

lib/Biblio/Citation/Parser/Citebase.pm

raw ◀ ▶
1 Debian patch touch this file
1 package Biblio::Citation::Parser::Citebase;
2
3 ######################################################################
4 #
5 # Biblio::Citation::Parser::CiteBase;
6 #
7 ######################################################################
8 #
9 # This file is part of ParaCite Tools (http://paracite.eprints.org/developers/)
10 #
11 # Copyright (c) 2004 University of Southampton, UK. SO17 1BJ.
12 #
13 # ParaTools is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # ParaTools is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with ParaTools; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #
27 ######################################################################
28
29 =pod
30
31 =head1 NAME
32
33 Biblio::Citation::Parser::Citebase - Citebase's citation parsing module
34
35 =head1 DESCRIPTION
36
37 This module is an updated (and hopefully improved) version of Zhuoan Jiao's citation-parsing modules.
38
39 =head1 SYNOPSIS
40
41 use Biblio::Citation::Parser::Citebase;
42 $parser = new Biblio::Citation::Parser::Citebase([$source_identifier]);
43 $metadata = $parser->parse($citation);
44 print "Author: ", $metadata->{aufirst}, " ", $metadata->{aulast}, "\n";
45
46 =cut
47
48 use strict;
49 use utf8;
50 use Time::localtime; # optional, used by OpCit project.
51 use vars qw(@ISA @EXPORT @EXPORT_OK);
52 use Biblio::Citation::Parser::Jiao::Utility qw(normalisation normalise_html);
53 use Text::Unidecode; # Used so we can just use a-z to match lowercase letters
54
55 use Exporter;
56 @ISA = qw(Exporter);
57
58 @EXPORT = qw();
59 @EXPORT_OK = qw(&normalise_name &normalise_date
60 &num_of_figures &print_out);
61 #@EXPORT_OK = qw(&normalise_name &normalisation &normalise_date
62 # &normalise_html &num_of_figures &print_out);
63
64 =pod
65
•66 =over
67
68 =item $p = new Biblio::Citation::Parser::Citebase([$citation],[$source_identifier]);
69
70 Create a new citation parser, optionally parsing $citation with $source_identifier. If a citation is given the return blessed hash will contain the structured data.
71
72 =cut
73
74 sub new {
75 my ($class,$citation,$sidentifier) = @_;
76 $class = ref $class ? $class->{'_class'} : $class; # I'm sure there's a better way of doing this
77 my $self;
78 if( $citation ) {
79 my %args = (
80 _class=>$class,
81 sourceID=>$sidentifier,
82 text=>$citation,
83 rest_text=>$citation,
84 );
85 @args{qw(
86 aufull aulast aufirst auinit authors atitle
87 title volume issue supl spage year targetURL
88 rest_text date targetID featureID
89 jnl_spos jnl_epos num_of_fig
90 )} = ();
91 $self = bless \%args, $class;
92 $self->find_metadata();
93 $self->find_featureID();
94
95 # OpenURL mapping
96 $self->{'id'} = $self->{'targetID'};
97 $self->{'pages'} = $self->{'spage'};
98 } else {
99 $self = bless {_class=>$class}, $class;
100 }
101 return $self;
102 }
103
104 =pod
105
106 =item $md = $p->parse($citation, [$source_identifier]);
107
108 Parses a string, $citation, and returns a blessed hash of the structured data.
109
•110 =back
111
112 =cut
113
114 # This is a very nasty hack to allow this method
115 sub parse { new(@_) }
116
117 sub initialize {
118 my $cite = shift;
119 my $text = shift || die "Requires citation text to parse";
120 my $sidentifier = shift;
121
122 $cite->{'text'} = $text;
123 $cite->{'aufull'} = undef;
124 $cite->{'aulast'} = undef;
125 $cite->{'aufirst'}= undef;
126 $cite->{'auinit'} = undef;
127 $cite->{'authors'}= undef;
128 $cite->{'atitle'} = undef;
129 $cite->{'title'} = undef;
130 $cite->{'volume'} = undef;
131 $cite->{'issue'} = undef;
132 $cite->{'supl'} = undef;
133 $cite->{'spage'} = undef;
134 $cite->{'year'} = undef;
135 $cite->{'targetURL'} = undef;
136
137 $cite->{'rest_text'} = $text;
138 $cite->{'date'} = undef;
139 $cite->{'sourceID'} = $sidentifier;
140 $cite->{'targetID'} = undef;
141 $cite->{'featureID'} = undef;
142 $cite->{'jnl_spos'} = undef;
143 $cite->{'jnl_epos'} = undef;
144 $cite->{'num_of_fig'}= undef;
145
146 $cite->find_metadata();
147 $cite->find_featureID();
148
149 # OpenURL mapping
150 $cite->{'id'} = $cite->{'targetID'};
151 $cite->{'pages'} = $cite->{'spage'};
152 }
153
154 #
155 # Actions
156 #
157 sub pre_process {
158 my $cite = shift;
159 my $Text = shift || $cite->{'text'};
160
161 $Text = normalisation($Text);
162 $Text = normalise_date($Text);
163 $Text = normalise_html($Text);
164 # remove front label to get accurate $nFig
165 # (Note: do not perform this for arXiv ref. like: "46(4), 90 (1993)")
166 # [Smith, 1998], [1], (1), (1a) ...
167 $Text =~ s/^\s*[\[(]\s* # bracket
168 ([^\])]+?)\s* # content
169 [\])]\s*//x; # bracket
170
171 # "1. Gary Smith, ...."
172 $Text =~ s/^\d+\s*\.\s+//;
173 # "1 Gary Smith, ...."
174 $Text =~ s/^\s*\d+ ([A-Z])/$1/;
175 # "2) Brand, P. ..."
176 $Text =~ s/^[\[\(]?\s*\w+\s*[\])]\s*//;
177
178 $cite->{'rest_text'} = $Text;
179
180 my $nFig = num_of_figures($Text);
181 $cite->{'num_of_fig'} = $nFig;
182
183 return $Text;
184 }
185
186 sub find_metadata {
187 my $cite = shift;
188
189 return 0 if (!defined($cite->{'text'}));
190
191 my $Text = $cite->pre_process($cite->{'text'});
192
193 $cite->{'targetID'} = $cite->complete_targetID($cite->find_targetID($cite->{'text'}));
194
195 # find URL
196 $cite->find_url();
197
198 my $nFig = $cite->{'num_of_fig'};
199
200 # find the authors
201 if ($cite->find_authors()) {
202 $cite->find_first_author()
203 };
204
205 # find article titile
206 $cite->find_atitle();
207
208 # only process references to 'journal' articles.
209 return 0 if ($nFig == 0) ; # no number, ignore.
210 return 0 if ($nFig >= 8); # too many numbers, maybe an error, ignore.
211 # return 0 if ($cite->{'rest_text'} =~ /\W(proc.|proceedings) of /i);
212
213 # extract 'supplement' first before find_vol_no_pg_year()
214 $cite->find_supplement();
215
216 if ($cite->find_vol_no_pg_year() or
217 $cite->find_vol_pg_year()) {
218
219 $cite->find_jnl_name();
220 return 1
221 };
222
223 if ($cite->guess_vol_no_pg()) {
224 $cite->find_jnl_name();
225 return 1;
226 };
227
228 if ($cite->find_vol_no() or
229 $cite->find_vol_supl()) {
230
231 $cite->find_jnl_name();
232 $cite->find_page();
233 $cite->find_year();
234
235 return 1;
236 };
237
238 if ($cite->guess_vol_pg()) {
239 $cite->find_year();
240 $cite->find_jnl_name();
241
242 return 1;
243 };
244
245 if ($cite->guess_vol_year()) {
246
247 $cite->find_page();
248 $cite->find_jnl_name();
249
250 return 1;
251 };
252
253
254 my $Count = 0;
255 $Count++ if ($cite->find_year());
256 $Count++ if ($cite->find_vol());
257 $Count++ if ($cite->find_issue());
258 $Count++ if ($cite->find_supplement());
259 $Count++ if ($cite->find_jnl_name());
260 $Count++ if ($cite->find_page());
261
262 return 1 if ($Count >=2 );
263
264 # Last-ditch get any three numbers
265 $cite->three_figs if $nFig <= 4;
266
267 # too few metadata
268 return 0
269 }
270
271 sub three_figs {
272 my $self = shift;
273 my $Text = $self->{'text'};
274
275 # Remove the year
276 return unless $Text =~ s/\(((?:19|20)\d{2})\)//;
277 $self->{year} = $1;
278
279 return unless $self->{year} or $Text =~ s/((?:19|20)\d{2})//;
280 $self->{year} = $1;
281
282 return unless $Text =~ s/(\d+)\s*-\s*[a-z]{0,2}(\d+)//i;
283 $self->{spage} = $1;
284 $self->{epage} = $2;
285
286 return unless $` =~ /(\d+)\D+/;
287 $self->{volume} = $1;
288
289 return 1;
290 }
291
292 my @arXiv = qw(astro-ph cond-mat gr-qc hep-ex hep-lat hep-ph hep-th
293 math-ph nucl-ex nucl-th physics quant-ph
294 adap-org alg-geom chao-dyn chem-ph cmp-lg
295 comp-gas cs dg-ga funct-an math mtrl-th
296 neuro-cel neuro-dev neuro-sys nlin nlin-sys
297 patt-sol plasm-ph q-alg solv-int supr-con
298 math.AG math.AT math.AP math.CT math.CA math.CO math.CV
299 math.DG math.DS math.FA math.GM math.GN math.GT
300 math.GR math.HO math.KT math.LA math.LO math.MP
301 math.MG math.NT math.NA math.OA math.OC math.PR math.QA
302 math.RT math.RA math.SC math.SP math.SG);
303 my %subarXiv;
304 my $subarXivre = '';
305 foreach my $sa (@arXiv) {
306 my $re = $sa;
307 $re =~ s/(\W)/$1?/g;
308 $subarXivre .= "(?:$re)|";
309 $re =~ s/\W//g;
310 $sa =~ s/^math(\.\w\w)/math/i; # Fix to make maths identifiers match
311 $subarXiv{$re} = $sa;
312 }
313 chop($subarXivre);
314 $subarXivre = "($subarXivre)\\s*.\\s*(\\d{7})";
315
316 sub complete_targetID {
317 my $self = shift;
318 my $tid = shift || return;
319
320 return $tid if $tid =~ /^oai:/;
321
322 my $sid = $self->{'sourceID'};
323 if( !defined($sid) && $tid =~ /^$subarXivre.*$/oi ) {
324 my ($sa,$no) = ($1,$2);
325 $sa =~ s/\W//g;
326 return "oai:arXiv.org:".$subarXiv{$sa}."/".$no;
327 }
328 if( !$sid ) {
329 warn "Warning: Unable to expand \"$tid\" as no sourceID given";
330 return;
331 }
332 return unless ($sid =~ /oai\:([^\:]+)\:([^\:\/]+)/);
333 my ($axv, $subaxv) = ($1,$2);
334
335 $tid =~ s/.(\d{7})/\/$1/;
336 if( $tid =~ /^[a-zA-Z]{2}/ && $tid =~ /^$subarXivre.*$/oi ) {
337 my ($sa,$no) = ($1,$2);
338 $sa =~ s/\W//g;
339 return "oai:$axv:".$subarXiv{$sa}."/".$no; # normalise subarXiv component
340 }
341 if( $tid =~ /^\d/ ) {
342 return "oai:$axv:$subaxv\/$tid";
343 }
344 return;
345 }
346
347 # Copied (mostly) from Parser::arXivCite
348 sub find_targetID {
349 my ($self,$cite) = @_;
350
351 # remove multiple spacing/tabs etc.
352 $cite =~ s/\s+/ /sg;
353 # remove space around '.' (math. DG => math.DB)
354 $cite =~ s/\s*\.\s*/\./sg;
355
356 # e.g. cond-mat/9910162
357 if( $cite =~ /\b((?:\w+-\w+).\d{7})(?:v\d+)?\b/ && $1 =~ /($subarXivre)/oi ) {
358 return $1;
359 }
360
361 # e.g. math.GB/9912001
362 if( $cite =~ /\b((?:\w+\.\w+).\d{7})(?:v\d+)?\b/ && $1 =~ /($subarXivre)/oi ) {
363 return $1;
364 }
365
366 # e.g. math/AG0206084, see oai:arXiv.org:math/0301128
367 if( $cite =~ /\b((?:\w+\/\w\w)\d{7})(?:v\d+)?\b/ ) {
368 my $id = $1;
369 $id =~ s/(\w+)\/(\D+)/$1.$2\//;
370 if( $id =~ /($subarXivre)/oi ) {
371 return $1;
372 }
373 }
374
375 # e.g. physics/9912001
376 if( $cite =~ /\b((?:\w+).\d{7})(?:v\d+)?\b/ && $1 =~ /($subarXivre)/oi ) {
377 return $1;
378 }
379
380 # e.g. 9912001
381 if( $cite =~ /\b(\d{2})([01][0-9])(\d{3})\b/ ) {
382 my ($year, $month, $i) = ($1,$2,$3);
383 if( $year < 91 ) {
384 $year += 2000;
385 } else {
386 $year += 1900;
387 }
388 my $cyear = localtime->year() + 1900;
389 if( $month >= 1 && $month <= 12 && $year <= $cyear ) {
390 return $1.$2.$3;
391 }
392 }
393
394 return;
395 }
396
397 sub find_atitle {
398 my $cite = shift;
399 my $Text = $cite->{'rest_text'};
400
401 # title is quoted.
402 # return 0 if ($Text !~ /(['"])/); #
403 # my $Qt = $1;
404 # ignore ' case, because author nams may contain ', e.g.
405 # A. I. L'vov, V. A. Petrun'kin, and M. Schumacher,
406 # Phys. Rev. C 55, 359 (1997)
407 return 0 if ($Text !~ /"/);
408
409 if ($Text =~ /"(.+?)"\s*\.?/ and
410 word_count($1) >= 2) {
411 my $Guess_title = $1;
412 return 0 if ($Guess_title =~ /^http:/i);
413
414 $cite->{'atitle'} = $Guess_title;
415 # use ';' !
416 # $Text =~ s/$Qt(.+?)$Qt\s*\.?/;/o;
417 # $Text =~ s/"[^"]+"\s*\.?/;/;
418 $Text =~ s/"[^"]+"/" "/;
419 # $Text =~ s/[,;.]\s*[,;.]/,/g; # doesn't work
420 while ($Text =~ /[,;.]\s*[,;.]/g) {
421 $Text =~ s/[,;.]\s*[,;.]/,/
422 };
423 $Text =~ s/^[;" ]+//;
424 $cite->{'rest_text'} = $Text;
425 return 1
426 };
427
428 return 0
429 }
430
431 # for the OpCit Project .
432 sub find_featureID {
433 my $cite = shift;
434
435 my $featureID = '';
436 $featureID .= "v$cite->{'volume'}" if ($cite->{'volume'});
437 $featureID .= ":n$cite->{'issue'}" if ($cite->{'issue'});
438 $featureID .= ":s$cite->{'supl'}" if ($cite->{'supl'});
439 $featureID .= ":p$cite->{'spage'}" if ($cite->{'spage'});
440 $featureID .= ":y$cite->{'year'}" if ($cite->{'year'});
441
442 # tidy up
443 # $featureID =~ s/:[nsp]\s*:/:/g; # doesn't work.
444 while ($featureID =~ /:[nsp]\s*:/g) {
445 $featureID =~ s/:[nsp]\s*:/:/
446 };
447 $featureID =~ s/^://;
448 $featureID =~ s/\s+//g;
449
450 my @Features = split(':', $featureID);
451
452 # ignore those having too few metadata
453 if (scalar(@Features) >= 2) {
454 # standardize
455 $featureID = lc($featureID);
456 $cite->{'featureID'} = $featureID;
457 };
458 }
459
460 sub create_refID {
461 my $cite = shift;
462 my $refID;
463 if ($cite->{'targetID'}) {
464 $cite->{refID} = $cite->{'sourceID'}.':'.$cite->{'targetID'};
465 }
466 elsif ($cite->{'featureID'}) {
467 $cite->{refID} = $cite->{'sourceID'}.':'.$cite->{'featureID'};
468 };
469 }
470
471 sub find_authors {
472 my $cite = shift;
473 my $Text = $cite->{'rest_text'};
474
475 my $aText = locate_authors($Text);
476 return 0 if ($aText eq '' or $aText =~ /^\W+$/);
477
478 my @Chunks = ();
479 @Chunks = split(/\s*[,;:\&]\s*/, $aText);
480
481 # ignore text longer than 4 words (don't count initials)
482 return 0 if (word_count($Chunks[0])>4 and no_initials($Chunks[0]));
483
484 my($author, $Authors) = ('','');
485 while (@Chunks) {
486 if (scalar(@Chunks)==1) {
487 last if !full_name($Chunks[0]);
488 $author = normalise_name($Chunks[0]);
489 $Authors = "$Authors:$author";
490 last
491 };
492
493
494 # (1) forename and surname are not separated by [,;].
495 if (full_name($Chunks[0])){
496 if ($Chunks[1] =~ /^\s*Jr\.?\s*$/i) {
497 $author = "$Chunks[0], $Chunks[1]";
498 $author = normalise_name($author);
499 $Authors = "$Authors:$author";
500 splice(@Chunks, 0, 2); # remove the first two
501 next
502 }
503 elsif (!only_initials($Chunks[1])) {
504 $author = normalise_name($Chunks[0]);
505 $Authors = "$Authors:$author";
506 shift(@Chunks);
507 next
508 }
509 }
510 elsif (full_name($Chunks[1])) {
511 # $Chunks[0] is not a name, skip.
512 shift @Chunks;
513 next
514 };
515
516 # (2) forename and surname are separated by [,;].
517 # Ignore text containing too many words.
518 my $aFull = "$Chunks[0] $Chunks[1]";
519 my @abbr = ();
520 last if (word_count($aFull) > 4);
521 last if ($aFull =~ /[\d\/]+/);
522
523 # journal title maybe mixed up with the name
524 last if (@abbr = ($aFull =~ /\w\w\./g) and (@abbr >= 2));
525
526 # surname first.
527 # "Oemler, A., Jr. and Lynds, C. R. 1975, ApJ, 199, 558"
528 if (scalar(@Chunks) > 2) {
529 if (is_surname($Chunks[0]) and
530 has_initials($Chunks[1]) and
531 $Chunks[2] =~ /^\s*Jr\.?\s*$/i) {
532 $author = "$Chunks[1] $Chunks[0], Jr";
533 $author = normalise_name($author);
534 $Authors = "$Authors:$author";
535 splice(@Chunks, 0, 3); # remove the first three
536 next
537 };
538 };
539
540 # surname first
541 # "Reisenegger, A. and Miralda-Escude, J. 1995, ApJ, 449, 476
542 if (is_surname($Chunks[0]) and
543 has_initials($Chunks[1])) {
544 if ($Chunks[1] =~ /(.+?\.?)\s*Jr\.?\s*$/i){
545 $author = "$1 $Chunks[0], Jr";
546 }
547 else
548 {
549 $author = "$Chunks[1] $Chunks[0]";
550 };
551 $author = normalise_name($author);
552 $Authors = "$Authors:$author";
553 splice(@Chunks, 0, 2); # remove the first two
554 next
555 };
556
557 # forename first
558 if (only_initials($Chunks[0]) and
559 is_surname($Chunks[1])) {
560 if ($Chunks[0] =~ /(.+?[. ])\s*Jr\.?\s*$/i){
561 $author = "$1 $Chunks[1], Jr";
562 }
563 else
564 {
565 $author = $aFull
566 };
567 $author = normalise_name($author);
568 $Authors = "$Authors:$author";
569 splice(@Chunks, 0, 2); # remove the first two
570 next
571 };
572
573 # 'Liu, Gong', hard to tell which is the surname;
574 if (no_initials($Chunks[0]) and
575 no_initials($Chunks[1])) {
576 if (word_count($aFull) <= 4 ) {
577 $author = normalise_name($aFull);
578 $Authors = "$Authors:$author";
579 splice(@Chunks, 0, 2); # remove the first two
580 next
581 }
582 };
583
584 # cannot determin the author name
585 last
586
587 }; # end of while
588
589 return 0 if ($Authors eq '');
590 $Authors =~ s/^://;
591 $cite->{'authors'} = $Authors;
592 }
593
594 sub find_first_author {
595 my $cite = shift;
596
597 return 0 if (!defined($cite->{'authors'}));
598
599 my ($author) = split(':', $cite->{'authors'}, 2);
600 $cite->{'aufull'} = $author;
601 if( $author =~ /(.*)[\s\._]([^\s\.]+)/ ) {
602 $cite->{'aulast'} = $2;
603 $cite->{'aufirst'} = $1;
604 }
605 }
606
607 # locate_authors
608 sub locate_authors {
609 my $Text = shift;
610
611 $Text =~ s/^\s*For .*?review(s)?\W+//i;
612 $Text =~ s/^\s*(see )?also //i;
613 $Text =~ s/^\s*see[, ]\s*for example\W+//i;
614 $Text =~ s/^\s*see e\.g\.\W+//i;
615 my $aText = $Text;
616
617 # author name(s) is assumed to be in front of a consecutive
618 # 4 words, e.g. J. A. Harvey. String Duality and Non-supersymmetric
619 # Strings.
620 # if ($Text =~ /\b([\w\-'`"]+\s+){3,}[\w\-'"]+\b/){
621 if ($Text =~ /\.\s+([\w\-'`"]+\s+){3,}[\w\-'"]{2,}\b/){
622 $aText = $`;
623 };
624
625 if ($Text =~ /[,;]\s*([\w\-'`"]{2,}\s+){3,}[\w\-'"]{2,}\b/) {
626 $aText = $`;
627 };
628 # the above has truncated too much.
629 # "S. Popescu and Sudbery G. A. Multi-particle entanglement ..."
630 if (only_initials($aText)) {
631 $aText = $Text
632 };
633
634 if ($aText =~ /[,:; ]\s*[a-z][\w\-'"]*\s+([a-z0-9\-'"]+\s+)*?[a-z0-9\-'"]{4,}(\b|$)/) { # "[6] M.Gotay, Constraints, reduction and quantization,
635 # J. Math. Phys. (1986) 2051.
636 $aText = $`;
637 };
638
639 # Or before the following sybmols.
640 # if ($aText =~ /["\[\(]/) {
641 if ($aText =~ /[:"\[\(]/) {
642 $aText = $`
643 };
644
645
646 # before '/', e.g. "Halzen F. astro-ph/0001001"
647 if ($aText =~ /\S+\//) {
648 $aText = $`
649 };
650
651 # before any number
652 if ($aText =~ /\d+/i) {
653 $aText = $`
654 };
655
656 # "14. A. J. Leggett, in Percolation, Localization and ..."
657 # or "M. Göckeler, et al., hep-lat/9608033."
658 if ($aText =~ /[,;: ]\s*(?:in )|(?:et\.?\s+al\.?\b)/i) {
659 $aText = $`
660 };
661
662 # last author name after 'and'.
663 if ($aText =~ /[,; ]\s*and ([^,;:]+)[,:;]([^,;:]+)/i) {
664 my $Aft1 = $1;
665 my $Aft2 = $2;
666 if (full_name($Aft1)) {
667 $aText = $` .", $Aft1";
668 } else {
669 $aText = $` .", $Aft1, $Aft2"
670 }
671 };
672
673 #
674 # tidy up
675 #
676 # remove non-alphabets
677 $aText =~ s/^[^a-z]+//i;
678 $aText =~ s/^by //i;
679 $aText =~ s/[,; ]+and /,/i;
680 $aText =~ s/[,; ]+et\.?\s+al\.?([,; ]+|$)/, et al,/i;
681 $aText =~ s/[,;:.]+\s*$//;
682 return $aText
683 };
684
685 # This subroutine needs re-written; not in use now.
686 sub locate_book {
687 my $cite = shift;
688 my $Text = $cite->{'rest_text'};
689
690 if ($Text =~ /\W+in\s+(.+?)\W+(ed|eds|edited)\.?(\W|$)/) {
691 $$cite{book} = $1;
692 return 1
693 };
694 return 0
695
696 }
697
698 sub find_vol_no {
699 my $cite = shift;
700 my $Text = $cite->{'rest_text'};
701
702 if ($Text =~ s/[,;. ]\s*(?:volume|vol|v)?\.?\s*(\d+)\s*[ ,;]\s*(?:n|no|issue|\#)\.?\s*(\d+)\b/$1/is) {
703
704 $cite->{'volume'} = $2;
705 $cite->{'issue'} = $3;
706 $cite->{'jnl_epos'} = length($`);
707 $cite->{'rest_text'} = $Text;
708 return 1
709 }
710 else { return 0}
711 }
712
713 sub find_vol_supl {
714 my $cite = shift;
715 my $Text = $cite->{'rest_text'};
716
717 if ($Text =~ s/(\s|,|;|\.)\s*(?:volume|vol|v)?\.?\s*(\d+)\s*[\s,;]\s*(?:supl|supplement)\.?\s*(\d+)\b/$1/is) {
718
719 $cite->{'volume'} = $2;
720 $cite->{'supl'} = $3;
721 $cite->{'jnl_epos'} = length($`);
722 $cite->{'rest_text'} = $Text;
723 }
724 }
725
726
727 sub find_vol {
728 my $cite = shift;
729 my $Text = $cite->{'rest_text'};
730
731 if ($Text =~ s/[,;:\. ]\s*(?:volume|vol)[\. ]\s*([a-z]*\d+[a-z]*)\b//i) {
732 $cite->{'volume'} = $1;
733 $cite->{'rest_text'} = $Text;
734 return
735 };
736
737 # "..., Vol9 ..."
738 if ($Text =~ s/[,;:\. ]\s*(?:volume|vol)(\d+[a-z]*)\b//i) {
739 $cite->{'volume'} = $1;
740 $cite->{'rest_text'} = $Text;
741 return
742 };
743
744 if ($Text =~ s/[,;:\. ]\s*(?:volume|vol)(\d+[a-z]*)\b//i) {
745 $cite->{'volume'} = $1;
746 $cite->{'rest_text'} = $Text;
747 return
748 };
749
750 # beware: "Smith, V. 1990, Phys. Rev. A. v. 10 ..."
751 while ($Text =~ /[,;\. ]\s*V\s*[\. ]\s*([a-z]*\d+[a-z]*)\b/ig){
752 my $Guess_vol = $1;
753 next if ($Guess_vol =~ /(19|20)\d\d/);
754
755 $cite->{'volume'} = $Guess_vol;
756 $Text =~ s/[,;\. ]\s*V\s*[\. ]\s*[a-z]*\d+[a-z]\b//i;
757 $cite->{'rest_text'} = $Text;
758 return
759 };
760
761 # "... v10, ..."
762 if ($Text =~ s/[,;:\. ]\s*V(\d+[a-z]*)\b//i) {
763 $cite->{'volume'} = $1;
764 $cite->{'rest_text'} = $Text;
765 return
766 };
767 }
768
769 sub find_issue {
770 my $cite = shift;
771 my $Text = $cite->{'rest_text'};
772
773 if ($Text =~ s/[,;:. ]\s*(?:number|issue|num|no|Nr|\#)[. ]\s*([a-z]*\d+[a-z]*)\b//i) {
774 $cite->{'issue'} = $1;
775 $cite->{'rest_text'} = $Text;
776 return
777 };
778
779 # e.g. " ...No10, ..."
780 if ($Text =~ s/[,;:. ]\s*(?:number|issue|num|no|Nr)(\d+[a-z]*)\b//i) {
781 $cite->{'issue'} = $1;
782 $cite->{'rest_text'} = $Text;
783 return
784 };
785
786 while ($Text =~ /[,;:. ]\s*N\s*[. ]\s*([a-z]*\d+[a-z]*)\b/ig){
787 my $Guess_issue = $1;
788 next if ($Guess_issue =~ /(19|20)\d\d/);
789
790 $cite->{'issue'} = $Guess_issue;
791 $Text =~ s/[,;. ]\s*N\s*[. ]\s*[a-z]*\d+[a-z]*\b//i;
792 return
793 };
794
795 if ($Text =~ s/[,;:. ]\s*(?:n|\#|\#\s+)(\d+[a-z]*)\b//i) {
796 $cite->{'issue'} = $1;
797 $cite->{'rest_text'} = $Text;
798 return
799 };
800
801
802 }
803
804 sub find_supplement {
805 my $cite = shift;
806 my $Text = $cite->{'rest_text'};
807
808 if ($Text =~ s/[,;:. ]\s*(?:suppl|supplement)\.?\s*(\d+)\b//i) {
809 $cite->{'supl'} = $1;
810 $cite->{'num_of_fig'} = $cite->{'num_of_fig'} - 1;
811 $cite->{'rest_text'} = $Text
812 }
813 }
814
815
816 sub find_url {
817 my $cite = shift;
818 my $Text = $cite->{'rest_text'};
819
820 if ($Text =~ s/\b(http:\/\/[^\s]+)['"]>/ /i){
821 $cite->{'targetURL'} = $1;
822 $cite->{'rest_text'} = $Text;
823 return 1
824 };
825
826 if ($Text =~ s/\b(http:\/\/[^\s>]+)(?:\s|$)/ /i){
827 $cite->{'targetURL'} = $1;
828 $cite->{'targetURL'} =~ s/[.,;]$//;
829 $cite->{'rest_text'} = $Text;
830 return 1
831 };
832
833 return 0
834 }
835
836 sub find_page {
837 my $cite = shift;
838 my $Text = $cite->{'rest_text'};
839
840 # keep the order of the pattern matching.
841
842 # '... p.20, p 20, ...'
843 if ($Text =~ s/[,;:. ]\s*(?:pages|page|pp)\s*[.# ]\s*([a-z]*\d+[a-z]*)\b//i) {
844 $cite->{'spage'} = $1;
845 $cite->{'rest_text'} = $Text;
846 return
847 };
848
849 # " ... pp20, ..."
850 if ($Text =~ s/[,;:. ]\s*(?:pages|page|pp)(\d+[a-z]*)\b//i) {
851 $cite->{'spage'} = $1;
852 $cite->{'rest_text'} = $Text;
853 return
854 };
855
856 # ... p. 1990-1993
857 if ($Text =~ s/[,;. ]\s*(?:p)\s*[. ]\s*
858 ([a-z]*\d+[a-z]*)\s*\-\s*[a-z]*d+[a-z]*\b//xi) {
859
860 $cite->{'spage'} = $1;
861 $cite->{'rest_text'} = $Text;
862 return
863 };
864
865 # Beaware "Smith P. 1990, ..., p. 100"
866 while ($Text =~ /[,;. ]\s*p\s*[. ]\s*([a-z]*\d+[a-z]*)\s*(?!\-)/ig){
867 my $Guess_page = $1;
868 next if ($Guess_page =~ /(19|20)\d\d/);
869
870 $cite->{'spage'} = $Guess_page;
871 $Text =~ s/[,;. ]\s*p\s*[. ]\s*[a-z]*\d+[a-z]*\s*(?!\-)//i;
872 $cite->{'rest_text'} = $Text;
873 return
874 };
875
876 # " ... p20, ..."
877 if ($Text =~ s/[,;:. ]\s*p(\d+[a-z]*)\b//i) {
878 $cite->{'spage'} = $1;
879 $cite->{'rest_text'} = $Text;
880 return
881 };
882 }
883
884
885 sub find_year {
886 my $cite = shift;
887
888 return 1 if ($cite->{'year'});
889
890 my $Text = $cite->{'rest_text'};
891
892 # priority is given to (1989) type.
893 if ($Text =~ s/\(((19|20)\d\d)\w?\)//) {
894 $cite->{'year'} = $1;
895 $cite->{'rest_text'} = $Text;
896 return 1
897 };
898
899 # year like numbers not before/after a '-'
900 # e.g. 1966-1988 may indicate a page range.
901 if ($Text =~ /[^\w\-"]((19|20)\d\d)\w?([^\w\-"]|$)/i) {
902
903 $cite->{'year'} = $1;
904 $Text =~ "\Q$` $'\E";
905 $cite->{'rest_text'} = $Text;
906 return 1
907 };
908
909 return 0;
910 }
911
912 # Apt'e, C., et al. ACM Transactions on Information Systems 12, 3, 233-251
913 sub guess_vol_no_pg {
914 my $cite = shift;
915 return 1 if ($cite->{'volume'} and $cite->{'issue'} and
916 $cite->{'spage'});
917 return 0 if ($cite->{'num_of_fig'} < 3);
918
919 my $Text = $cite->{'rest_text'};
920
921 # change (1,1) alike to ().
922 $Text =~ s/\(\d+\s*,\s*\d+\s*\)/\(\)/g;
923 $Text =~ s/\(\d+\s*;\s*\d+\s*\)/\(\)/g;
924
925 if ($Text =~
926 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
927 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
928 [^\w\/.-]+(?:pages|page|pp|p)?\.?
929 \s*([a-z]*?\d+[a-z]*?)(?:\s*-\s*[a-z]*?\d+[a-z]*?)?
930 (\W*|$)/xi) {
931
932 $cite->{'volume'} = $1;
933 $cite->{'issue'} = $2;
934 $cite->{'spage'} = $3;
935 $cite->{'jnl_epos'} = length($`) + 1;
936
937 return 1
938 };
939
940 return 0
941
942 }
943
944
945 # '15:190' (15A:190-195, 14-15:190-180, or "Astrophys. J. 8, 103");
946 # Called this after '{find_vol_{no}_pg_year}' failed.
947 sub guess_vol_pg {
948 my $cite = shift;
949 return 1 if ($cite->{'volume'} and $cite->{'spage'});
950 return 0 if ($cite->{'num_of_fig'} < 2);
951
952 my $Text = $cite->{'rest_text'};
953
954 # change (1,1) alike to ().
955 $Text =~ s/\(\d+\s*,\s*\d+\s*\)/\(\)/g;
956 $Text =~ s/\(\d+\s*;\s*\d+\s*\)/\(\)/g;
957
958 # 15A:190-195 type
959 if ($Text =~ s/[^\w\/.-]([a-z]*?\d+[a-z]*?)\s*:\s*([a-z]*?\d+[a-z]*?)\s*
960 (-\s*[a-z]*?\d+[a-z]*?)?(\W|$)/$4/xi) {
961 $cite->{'volume'} = $1;
962 $cite->{'spage'} = $2;
963 $cite->{'jnl_epos'} = length($`) + 1;
964
965 $cite->{'rest_text'} = $Text;
966 return 1
967 };
968
969 # Astrophys. J. Lett., 452, p.L91-L93
970 # AIP, vol 307, p.117, New York (1994).
971 # Pub. Astron. Soc. Japan, 2000, p.52
972 if ($Text =~
973 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
974 [^\w\/.-]*,\s*(?:p|pp|page|pages)[. ]\s*([a-z]*?\d+[a-z]*?)\s*
975 (-\s*[a-z]*?\d+[a-z]*?)?(?:\W|$)/xi) {
976
977 my $Guess_vol = $1;
978 $cite->{'spage'} = $2;
979 my $Guess_jnl_epos = length($`) + 1; # prematch
980
981 if ($Guess_vol =~ /^(19|20)\d\d[a-z]?$/i) {
982 $cite->{'year'} = $Guess_vol;
983 $cite->{'rest_text'} =~
984 s/([^\w\/.-])(?:volume|vol\.?|v\.?)?\s*[a-z]*?\d+[a-z]*?\s*,\s*(?:p|pp|page|pages)\s*\.?[a-z]*?\d+[a-z]*?\s*(-\s*[a-z]*?\d+[a-z]*?)?(\W|$)/$1/i;
985 return 0
986 };
987 $cite->{'volume'} = $Guess_vol;
988 $cite->{'jnl_epos'} = $Guess_jnl_epos;
989 $cite->{'rest_text'} =~
990 s/([^\w\/.-])[a-z]*?\d+[a-z]*?\s*,\s*(?:p|pp|page|pages)\s*\.?[a-z]*?\d+[a-z]*?\s*(-\s*[a-z]*?\d+[a-z]*?)?(\W|$)/$1/i;
991 return 1
992 };
993
994 # Elias, J. 1994, NOAO Newsletter, No. 37, 1
995 if ($Text =~
996 /[^\w\/.-](?:n|no|num|issue)[. ]\s*([a-z]*?\d+[a-z]*?) # volume
997 [^\w\/.-]*,\s*(?:p|pp|page|pages)?\.?\s*([a-z]*?\d+[a-z]*?)\s*
998 (-\s*[a-z]*?\d+[a-z]*?)?(?:\W|$)/xi) {
999
1000 $cite->{'issue'} = $1;
1001 $cite->{'spage'} = $2;
1002 $cite->{'jnl_epos'} = length($`) + 1; # prematch
1003 $cite->{'rest_text'} =~
1004 s/([^\w\/.-])(?:n|no|num|issue)[. ]\s*[a-z]*?\d+[a-z]*?[^\w\/.-]*,\s*(?:p|pp|page|pages)?\.?\s*([a-z]*?\d+[a-z]*?)\s*(-\s*[a-z]*?\d+[a-z]*?)?(?:\W|$)/$1/i;
1005 return 1
1006 };
1007
1008 # match page range.
1009 # Phys. Rev. A 4, 52-60
1010 # Pub. Astron. Soc. Japan, 1998, 52-60
1011 if ($Text =~ /[^\w\/.-]([a-z]*?\d+[a-z]*?) # volume or year
1012 [^\w\/.-]*[, ]\s*([a-z]*?\d+[a-z]*?)\s* # pages
1013 -\s*[a-z]*?\d+[a-z]*?(?:[^\w-]|$)/xi) {
1014
1015 my $Guess_vol = $1;
1016 $cite->{'spage'} = $2;
1017 my $Guess_jnl_epos = length($`) + 1; # prematch
1018
1019 if ($Guess_vol =~ /^(19|20)\d\d[a-z]?$/i) {
1020 $cite->{'year'} = $Guess_vol;
1021 $cite->{'rest_text'} =~
1022 s/([^\w\/.-])[a-z]*?\d+[a-z]*?\s*[, ]\s*([a-z]*?\d+[a-z]*?)\s*-\s*[a-z]*?\d+[a-z]*?(?:[^\w\/.-]|$)/$1/i;
1023 return 0
1024 };
1025 $cite->{'volume'} = $Guess_vol;
1026 $cite->{'jnl_epos'} = $Guess_jnl_epos;
1027 $cite->{'rest_text'} =~ s/([^\w\/.-])[a-z]*?\d+[a-z]*?\s*,\s*([a-z]*?\d+[a-z]*?)\s*-\s*[a-z]*?\d+[a-z]*?(?:[^\w\/.-]|$)/$1/i;
1028
1029 return 1
1030 };
1031
1032 # Phys. Rev. B 38, 2297. (Phys. Rev. B 38 2297)
1033 # Pub. Astron. Soc. Japan, 2000, 52.
1034 if ($Text =~ /[^\w\/.-]([a-uw-z]*?\d+[a-z]*?)
1035 [^\w\/.-]*[, ]\s*([a-z]?\d+[a-z]?)(?:[^\w\/.-]|$)/xi) {
1036
1037 my $Guess_vol = $1;
1038 my $Guess_page = $2;
1039 $cite->{'jnl_epos'} = length($`) + 1;
1040
1041 if ($Guess_vol =~ /^(19|20)\d\d[a-z]?$/i) {
1042 $cite->{'year'} = $Guess_vol;
1043 } else {
1044 $cite->{'volume'} = $Guess_vol;
1045 };
1046
1047 if ($Guess_page =~ /^(19|20)\d\d[a-z]?$/i) {
1048 $cite->{'year'} = $Guess_page;
1049 } else {
1050 $cite->{'spage'} = $Guess_page;
1051 };
1052
1053 $cite->{'rest_text'} =~
1054 s/([^\w\/.-])[a-z]*?\d+[a-z]*?[^\w\/.-]*[, ]\s*[a-z]*?\d+[a-z]*?(?:[^\w\/.-]|$)/$1/i;
1055 return 1 if ($cite->{'volume'} and $cite->{'spage'});
1056 return 0
1057 };
1058
1059 return 0
1060 };
1061
1062 #
1063 # G. Smith and H. Gray; Pub. Astron. Soc. Japan, 2000, vol. 52
1064 # To find $cite->{'jnl_epos'} currectly. Note that '2000' may be
1065 # regarded as the journal name (by subroutine find_vol).
1066 sub guess_vol_year {
1067 my $cite = shift;
1068 return 0 if ($cite->{'num_of_fig'} < 2);
1069
1070 my $Text = $cite->{'rest_text'};
1071
1072 # change (1,1) alike to ().
1073 $Text =~ s/\(\d+\s*,\s*\d+\s*\)/\(\)/g;
1074 $Text =~ s/\(\d+\s*;\s*\d+\s*\)/\(\)/g;
1075
1076 if ($Text =~
1077 /[^\w\/.-]\(?((19|20)\d\d)\w?\)?[^\w\/.-]*
1078 (?:volume|vol|v)\W*([a-oq-z]*?\d+[a-z]*?)(\W|$)/xis) {
1079
1080 $cite->{'year'} = $1;
1081 $cite->{'volume'} = $3;
1082 $cite->{'jnl_epos'} = length($`);
1083
1084 return 1
1085 };
1086
1087 # be aware: "Workshop on ..., p30 (1999)."
1088 if ($Text =~
1089 /[^\w\/.-](?:volume|vol|v)?\W*([a-oq-z]?\d+[a-z]?)
1090 [^\w\/.-]+\(?((19|20)\d\d)\w?\)?(\W|$)/xis) {
1091 $cite->{'volume'} = $1;
1092 $cite->{'year'} = $2;
1093 $cite->{'jnl_epos'} = length($`);
1094
1095 return 1
1096 };
1097
1098 return 0
1099 };
1100
1101 sub find_vol_no_pg_year {
1102 my $cite = shift;
1103 return 1 if ($cite->{'volume'} and $cite->{'issue'} and
1104 $cite->{'spage'} and $cite->{'year'});
1105 return 0 if ($cite->{'num_of_fig'} < 4);
1106
1107 my $Text = $cite->{'rest_text'};
1108
1109 # change (1,1) alike to ().
1110 $Text =~ s/\(\d+\s*,\s*\d+\s*\)/\(\)/g;
1111 $Text =~ s/\(\d+\s*;\s*\d+\s*\)/\(\)/g;
1112
1113 # Keep the following order of texting $Text;
1114 # Important: check 'year' at the end first.
1115
1116 # (A.1):
1117 # 'year' is at the end, within bracket.
1118 # ..., v.517, no. 1, p.190-200, (1999)
1119 # ..., 11(2), 100-105, (1999)
1120 if ($Text =~
1121 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1122 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
1123 [^\w\/.-]+(?:pages|page|pp|p)?\.?
1124 \s*([a-z]*?\d+[a-z]*?)(?:\s*-\s*[a-z]*?\d+[a-z]*?)?
1125 \W*\(((19|20)\d\d)[a-z]*?\)(\W|$)/xi) {
1126
1127 $cite->{'volume'} = $1;
1128 $cite->{'issue'} = $2;
1129 $cite->{'spage'} = $3;
1130 $cite->{'year'} = $4;
1131 $cite->{'jnl_epos'} = length($`) + 1;
1132
1133 return 1
1134 };
1135
1136 # (A.2) 'year' is in the middle, within bracket.
1137 # ..., 4(2), (1999), 100-105
1138 if ($Text =~
1139 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1140 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
1141 \W*\(((19|20)\d\d)[a-z]*?\) # year
1142 \W*(?:pages|page|pp|p)?\.?\s*([a-z]*?\d+[a-z]*?)(\W|$)/xi) {
1143
1144 $cite->{'volume'} = $1;
1145 $cite->{'issue'} = $2;
1146 $cite->{'year'} = $3;
1147 $cite->{'spage'} = $5;
1148 $cite->{'jnl_epos'} = length($`) + 1;
1149
1150 return 1
1151 };
1152
1153 # (A.3.1) 'year' is at the beginning, within bracket, after
1154 # journal title;
1155 # ...., (1999), 517, no. 1, p.190-200
1156 if ($Text =~
1157 /\(((19|20)\d\d)[a-z]*?\)[,.;\s:]* # year
1158 (?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1159 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
1160 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]*?\d+[a-z]*?)(\W|$)/ix)
1161 {
1162 $cite->{'year'} = $1;
1163 $cite->{'volume'} = $3;
1164 $cite->{'issue'} = $4;
1165 $cite->{'spage'} = $5;
1166 $cite->{'jnl_epos'} = length($`);
1167
1168 return 1;
1169 };
1170
1171 # (A.3.2) 'year' is at the beginning, within bracket, before
1172 # journal title;
1173 # ..., (1999),..., 517, no. 1, p.190-200
1174 if ($Text =~
1175 /\(((19|20)\d\d)[a-z]*?\) # year
1176 ([^(]+?)
1177 [^\w\/.-](?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1178 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
1179 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]*?\d+[a-z]*?)(\W|$)/ix){
1180 $cite->{'year'} = $1;
1181 $cite->{'volume'} = $4;
1182 $cite->{'issue'} = $5;
1183 $cite->{'spage'} = $6;
1184
1185 # $cite->{'jnl_spos'} = length($`);
1186 # $cite->locate_jnl_epos();
1187 $cite->{'jnl_epos'} = length($`) + length($1) +
1188 length($3);
1189 return 1;
1190 };
1191
1192
1193 # (B.1):
1194 # 'year' is at the end, but not in bracket;
1195 # ..., v.517, no. 1, p.190-200, 1999
1196 # ..., 517, no. 1, p.190-200, 1999
1197 if ($Text =~
1198 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1199 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
1200 [^\w\/.-]+(?:pages|page|pp|p)?\.?
1201 \s*([a-z]*?\d+[a-z]*?)(?:\s*-\s*[a-z]*?\d+[a-z]*?)?
1202 [^\w(:\/.-]+?((19|20)\d\d)[a-z]?\s*(?![)-])/xi) {
1203
1204 $cite->{'volume'} = $1;
1205 $cite->{'issue'} = $2;
1206 $cite->{'spage'} = $3;
1207 $cite->{'year'} = $4;
1208 $cite->{'jnl_epos'} = length($`) + 1;
1209
1210 return 1
1211 };
1212
1213
1214 # (B.2): 'year' is in the middle, but not in bracket.
1215 # 4(2), 1999, 100-105
1216 if ($Text =~
1217 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1218 [^\w\/.-]+(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?) # issue
1219 [^\w(:\/.-]+?\s*((19|20)\d\d)[a-z]? # year
1220 \s*[^\w\/.)-]+?\s*(?:pages|page|pp|p)?\.?\s*([a-z]*?\d+[a-z]*?)(\W|$)/xi) {
1221
1222 $cite->{'volume'} = $1;
1223 $cite->{'issue'} = $2;
1224 $cite->{'year'} = $3;
1225 $cite->{'spage'} = $5;
1226 $cite->{'jnl_epos'} = length($`) + 1;
1227
1228 return 1
1229 };
1230
1231 # (B.3.1): 'year' is at beginning, not in bracket, after title;
1232 # ..., 1999, v.517, no. 1, p.190-200
1233 # " ... 1890-1999", MNRAS, 2000, 4:1, p 1990
1234 if ($Text =~
1235 /[^"(\/.-]\s*((19|20)\d\d)[a-z]?[,;\.\s]+ # year
1236 (?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1237 [^\w\/.-]+?(?:n|no|number|issue|\#)?\.?\s*([a-z]*?\d+[a-z]*?)
1238 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]*?\d+[a-z]*?)(\W|$)/ix)
1239 {
1240 $cite->{'year'} = $1;
1241 $cite->{'volume'} = $3;
1242 $cite->{'issue'} = $4;
1243 $cite->{'spage'} = $5;
1244 $cite->{'jnl_epos'} = length($`) + 1;
1245 return 1
1246 };
1247
1248 # (B.3.2): 'year' is at beginning, not in bracket, before title;
1249 # 1999, ..., v.517, no. 1, p.190-200
1250 # 1999, ..., 517, no. 1, p.190-200
1251 # 1999, ..., 517(1), 190-200
1252 # NB: 1999, "... 1.5 factor ....", 517(1), 190-200
1253 # NB: B. Greene, editors, "Fields, Strings and Duality, TASI 1996",
1254 # pages 421-540, World Scientific, 1997.
1255 # " ... 1890-1999", MNRAS, 2000, 4:1, p 1990
1256 if ($Text =~
1257 /(?:^|[^"(\/.-])\s*((19|20)\d\d)[a-z]? # year
1258 [^\w:")(\/-][^(]*?
1259 [^\w\/.-](?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1260 [^\w\/.-]+?(?:n|no|number|issue|\#)?\.?\s*([a-z]?\d+[a-z]?)
1261 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]*?\d+[a-z]*?)(\W|$)/ix)
1262 {
1263 $cite->{'year'} = $1;
1264 $cite->{'volume'} = $3;
1265 $cite->{'issue'} = $4;
1266 $cite->{'spage'} = $5;
1267
1268 $cite->{'jnl_spos'} = length($`);
1269 $cite->locate_jnl_epos();
1270 return 1
1271 };
1272 return 0
1273 };
1274
1275
1276 # For cases where 'vol, page, year' can be identified correctly.
1277 sub find_vol_pg_year {
1278 my $cite = shift;
1279 return 1 if ($cite->{'volume'} and $cite->{'spage'} and
1280 $cite->{'year'});
1281 return 0 if ($cite->{'num_of_fig'} < 3);
1282
1283 my $Text = $cite->{'rest_text'};
1284
1285 # change (1,1) alike to ().
1286 $Text =~ s/\(\d+\s*,\s*\d+\s*\)/\(\)/g;
1287 $Text =~ s/\(\d+\s*;\s*\d+\s*\)/\(\)/g;
1288
1289 # (A.1) 'year' is at the end, within bracket.
1290 # ......, vol.8:100, (1999)
1291 # ......, 8:100, (1999)
1292 # ~~~~
1293 if ($Text =~
1294 /(?:^|[^\w\/.-])(?:volume|vol\.?|v\.?)?\s*([a-z]*\d+[a-z]*) # volume
1295 [^\w\/.-]+(?:pages|page|pp|p)?\.?
1296 \s*([a-z]?\d+[a-z]?)(?:\s*-\s*[a-z]?\d+[a-z]?)?
1297 \W*\(((19|20)\d\d)[a-z]?\)(\W|$)/xi) {
1298
1299 $cite->{'volume'} = $1;
1300 $cite->{'spage'} = $2;
1301 $cite->{'year'} = $3;
1302 $cite->{'jnl_epos'} = length($`) + 1;
1303
1304 return 1
1305 };
1306
1307 # (A.2) 'year' is in the middle, within bracket.
1308 # ......, 8, (1999), 100-105
1309 if ($Text =~
1310 /(?:^|[^\w\/.-])(?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1311 \W*\(((19|20)\d\d)[a-z]?\) # year
1312 \W*(?:pages|page|pp|p)?\.?
1313 \s*([a-z]?\d+[a-z]?)(?:\s*-\s*[a-z]?\d+[a-z]?)?(\W|$)/xi) {
1314
1315 $cite->{'volume'} = $1;
1316 $cite->{'year'} = $2;
1317 $cite->{'spage'} = $4;
1318 $cite->{'jnl_epos'} = length($`) + 1;
1319
1320 return 1
1321 };
1322
1323 # (A.3.1.) 'year' is at beginning, within bracket, after title;
1324 # ......, (1999) 517, 190-200
1325 if ($Text =~
1326 /\(((19|20)\d\d)[a-z]?\)[,;\.\s]* # year
1327 (?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1328 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/ix){
1329 $cite->{'year'} = $1;
1330 $cite->{'volume'} = $3;
1331 $cite->{'spage'}= $4;
1332 $cite->{'jnl_epos'} = length($`);
1333
1334 return 1;
1335 };
1336
1337 # (A.3.1.1) 'year' is at beginning, within bracket, after title;
1338 # not 'vol', buy 'No.@, e.g."..., (1999) No. 517, 190-200
1339 if ($Text =~
1340 /\(((19|20)\d\d)[a-z]?\)[,;\.\s]* # year
1341 (?:number|no|n)\.?\s*([a-z]*?\d+[a-z]*?) # volume
1342 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/ix){
1343 $cite->{'year'} = $1;
1344 $cite->{'volume'} = $3;
1345 $cite->{'spage'}= $4;
1346 $cite->{'jnl_epos'} = length($`);
1347
1348 return 1;
1349 };
1350
1351
1352 # (A.3.2.) 'year' is at beginning, within bracket, before title;
1353 # ..., (1999),..., 517, p.190-200
1354 if ($Text =~
1355 /\(((19|20)\d\d)[a-z]?\) # year
1356 [^(]+?
1357 [^\w\/.-](?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1358 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/ix){
1359 $cite->{'year'} = $1;
1360 $cite->{'volume'} = $3;
1361 $cite->{'spage'} = $4;
1362
1363 $cite->{'jnl_spos'} = length($`);
1364 $cite->locate_jnl_epos();
1365 return 1;
1366 };
1367
1368 # (B.1) 'year' is at the end, but not in bracket.
1369 # ......, vol.8:100, 1999
1370 # ......, 8:100, 1999
1371 # NB: ..., 1999, 8(1900)
1372 # ~~~~
1373 if ($Text =~
1374 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1375 [^\w\/.-]+(?:pages|page|pp|p)?\.?
1376 \s*([a-z]?\d+[a-z]?)(?:\s*-\s*[a-z]?\d+[a-z]?)? # page
1377 [^\w:(\/.-]+\s*((19|20)\d\d)[a-z]?\s*(?![)-])/xi) {
1378
1379 $cite->{'volume'} = $1;
1380 $cite->{'spage'} = $2;
1381 $cite->{'year'} = $3;
1382 $cite->{'jnl_epos'} = length($`) + 1;
1383
1384 return 1
1385 };
1386
1387 # (B.2) 'year' is in the middle, but not in brackets;
1388 # ... 8, 1999, p.100
1389 # ... 8, 1999, 100-105
1390 if ($Text =~
1391 /[^\w\/.-](?:volume|vol\.?|v\.?)?\s*([a-z]*?\d+[a-z]*?) # volume
1392 [^\w:(\/.-]+?\s*((19|20)\d\d)[a-z]? # year
1393 [^\w\/.)-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/xi)
1394 {
1395 $cite->{'volume'} = $1;
1396 $cite->{'year'} = $2;
1397 $cite->{'spage'} = $4;
1398 $cite->{'jnl_epos'} = length($`) + 1;
1399
1400 return 1
1401 };
1402
1403 # (B.3.1) 'year' is at the beginning,not in bracket, after title;
1404 # ..., 1999, 8, p1990
1405 if ($Text =~
1406 /[^\w\/.(-]\s*((19|20)\d\d)[a-z]?[,;\.\s]+
1407 (?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1408 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/ix){
1409 $cite->{'year'} = $1;
1410 $cite->{'volume'} = $3;
1411 $cite->{'spage'} = $4;
1412 $cite->{'jnl_epos'} = length($`)+1;
1413 return 1
1414 };
1415
1416 # (B.3.1.1) 'year' is at the beginning,not in bracket, after title;
1417 # no 'vol', but 'no.' e.g. ..., 1999, No. 8, p1990
1418 if ($Text =~
1419 /[^\w\/.(-]\s*((19|20)\d\d)[a-z]?[,;\.\s]+
1420 (?:number|no|n)\.?\s*([a-z]*?\d+[a-z]*?) # no volume, but issues
1421 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/ix){
1422 $cite->{'year'} = $1;
1423 $cite->{'issue'} = $3;
1424 $cite->{'spage'} = $4;
1425 $cite->{'jnl_epos'} = length($`)+1;
1426 return 1
1427 };
1428
1429
1430 # (B.3.2) 'year' is at beginning, not in bracket, before title;
1431 # 1999, ..., 8(100)
1432 if ($Text =~
1433 /((^|[^"\/.(-])\s*)(((19|20)\d\d)[a-z]?) # year
1434 ([^\w:")(\/][^(]*?)
1435 [^\w\/.-](?:volume|vol|v)?\.?\s*([a-z]*?\d+[a-z]*?) # volume
1436 [^\w\/.-]+(?:pages|page|pp|p)?\.?\s*([a-z]?\d+[a-z]?)(\W|$)/ix){
1437 $cite->{'year'} = $4;
1438 $cite->{'volume'} = $7;
1439 $cite->{'spage'} = $8;
1440
1441 # $cite->{'jnl_spos'} = length($`);
1442 # $cite->locate_jnl_epos();
1443 $cite->{'jnl_epos'} = length($`) + length($1) +
1444 length($3) + length($6);
1445 return 1
1446 };
1447
1448 return 0
1449 }
1450
1451
1452 # This subroutine is only called when the journal title is between
1453 # 'year' and 'vol/page', e.g. (a lot in astro-ph/)
1454 # Barnes, J., Efstathiou, G., 1987, ApJ, 319, 575
1455 # For other cases, the cite{'jnl_epos'} is determined while trying to
1456 # find out the vol, page, year, i.e. in 'find_vol_no_pg_year' kind
1457 # of subroutines.
1458 #
1459 sub locate_jnl_epos {
1460
1461 my $cite = shift;
1462 my $sPos = $cite->{'jnl_spos'};
1463 my $Text = substr($cite->{'rest_text'}, $sPos);
1464
1465 # $Text =~ s/(\W+)(?:pages|page|pp|p)\W*(\d+)/$1$2/;
1466 # $Text =~ s/-\d+[a-z]*?//; # pp100-105
1467
1468 # Before 'volume'
1469 if ($Text =~ /\b(?:volume|vol\.?|v\.?)\s*[a-z]*?\d+[a-z]*?(?![.0-9])/i) {
1470 $cite->{'jnl_epos'} = length($`) + $sPos;
1471 return 1
1472 };
1473
1474 # (1997) Phys. Rev. E56, No.3, 2875
1475 # (1997) Phys. Rev. A50, p.160
1476 if ($Text =~ /
1477 [^\w\/.-](?:volume|vol\.?|v\.?)?\s*[a-z]*?\d+[a-z]*? # volume
1478 [^\w\/.-]+(?:n |n.|no |no.|number |issue |\#|p |p.|pp.|page )\s*[a-z]*?\d+[a-z]*?
1479 (?:\W|$)/xi) {
1480 $cite->{'jnl_epos'} = length($`) + $sPos + 1 ;
1481 return 1
1482 };
1483
1484 # Before any two consecutive numbers, but not '123-127' style page.
1485 # Bertelli, G., 1999, ApJ, 517(1), ....
1486 # ApJ, 517:1, ...
1487 # ApJ, 517:367-380.
1488 #Beaware: J.K. Lanyi. 1999. Structure of bacteriorhodopsin at 1.55
1489 # angstrom resolution J. Mol. Bio. 291:899-911 ~~~~!
1490 if ($Text =~ /[^\w\/.-][a-z]*?\d+[a-z]*?\s*[,:(\s]\s*
1491 [a-z]?\d+[a-z]?(\W|$)/xi) {
1492 $cite->{'jnl_epos'} = length($`) + $sPos + 1;
1493 return 1
1494 };
1495
1496 return 0
1497 };
1498
1499
1500 sub find_jnl_name {
1501 my $cite = shift;
1502
1503 return 1 if ($cite->{'title'});
1504 return 0 if (! $cite->{'jnl_epos'});
1505
1506 # Assumption: journal name usually starts after a ',;'
1507 # or " which is used to enclose the article title,
1508 # and does not contain those symbols (i.e. ,;")
1509 #
1510 my $Text = substr($cite->{'rest_text'}, 0, $cite->{'jnl_epos'});
1511 my $Guess_jnl;
1512
1513 # Linden, N., et al. quantph/9711016 and Fortsch. Phys. 46, 567 (1998)
1514 #if ($Text =~ m{[^/]+/\w+\s*(.+)$}) {
1515 # $Text = $1
1516 # };
1517
1518 LOOP:
1519 # remove trailing symbols
1520 $Text =~ s/\s*[,;":\/\[\(]*\s*$//s;
1521
1522 # ignore anything in brackets (head/tail position)
1523 $Text =~ s/\W*\([^\)]+\)?\W*$//;
1524 $Text =~ s/^\s*\([^\)]+\)\W+//;
1525
1526 return 0 if ($Text eq '');
1527
1528 # quite many citations are like this:
1529 # "P. Reiter, et al:Phys. Rev. Lett. 82 (1999) 509"
1530 # hard to separate name from journal title. Other cases
1531 # are: '..., J.PHY.G:NUCL.PART.PHY.'. Have to compramise.
1532 if ($Text =~ /([^,;":?\/\[]+)$/) {
1533 $Guess_jnl = $1;
1534 $Guess_jnl =~ s/^['`]?\s*//;
1535 $Guess_jnl =~ s/\s+$//;
1536
1537 # ignore things in brackets
1538 $Guess_jnl =~ s/\W*\([^\)]+\)?\W*$//;
1539 $Guess_jnl =~ s/^\([^\)]+\)\W*//;
1540
1541 # journal name should begin and contain alphabet,
1542 # not only numbers; and should be longer than one
1543 # character. First remove 'year'
1544 $Guess_jnl =~ s/^.*?\(?(19|20)\d\d\w*\)?\W*//;
1545 if ($Guess_jnl =~ /^[a-z]\W*$/i) {
1546 $Text =~ s/[^,;":?\/\[]+$//;
1547 goto LOOP
1548 };
1549
1550 # No captital letters
1551 if ($Guess_jnl !~ /[A-Z]/) {
1552 $Text =~ s/[^,;":?\/\[]+$//;
1553 goto LOOP
1554 };
1555
1556 # "Report of ... Conf.:1. Introduction. Canadian Medical Association Journal"
1557 if ($Guess_jnl !~ /^[a-z]+/i) {
1558 my @gWords = split(/\s+/, $Guess_jnl);
1559
1560 if (scalar(@gWords) <= 3) {
1561 $Text =~ s/[^,;":?\/]+$//;
1562 goto LOOP
1563 }
1564 };
1565
1566 $Text = $Guess_jnl;
1567 }
1568 else {
1569 $Text =~ s/^[`']?\s*//;
1570 $Text =~ s/\s*$//;
1571
1572 # 'title' is after 'year' (other cases are dealt by
1573 # $cite->{'jnl_epos'} in 'find_vol_{no}_pg_year()'..
1574 if ($Text =~ /[,\s\(]+(19|20)\d\d[,\s\)]+\s*/) {
1575 $Text = $'
1576 };
1577 };
1578
1579 my $end_dot = 0;
1580 $end_dot = 1 if ($Text =~ /\.$/);
1581 my @Title_words = ();
1582 my @Words = ();
1583 my $i = 0;
1584
1585 # process from the end of the $Text to see if
1586 # a $Parts[$i] is (still) a part of a journal name.
1587 my @Parts = split(/\s*\.\s*/, $Text);
1588 for ($i = $#Parts; $i>=0; $i--) {
1589 next if ($Parts[$i] !~ /[a-z]/i);
1590
1591 # author name may be mixed into the journal title
1592 # e.g. "Popescu S. and G. A. Sudbery. J. of Phy ..."
1593 if ($i > 0 and $Parts[$i-1] =~ /^([A-Z][a-z]* )*and\s+[A-Z]$/) {
1594 last
1595 };
1596 if ($i > 1 and $Parts[$i-2] =~ /^([A-Z][a-z]* )*and\s+[A-Z]$/) {
1597 last if ($Parts[$i-1] =~ /^[A-Z]$/);
1598 };
1599
1600 # author name may be mixed into the journal title
1601 # e.g. "and Sudbery A. Multi-particle ..."
1602 if ($i > 0 and $Parts[$i] =~ /^[A-Z]$/) {
1603 # less than 4 words.
1604 if ($Parts[$i-1] =~ /^\S+\s+\S+(\s+\S+){0,2}$/ and
1605 $Parts[$i-1] =~ /^(and )?[A-Z].+?[A-Z]$/){
1606 last
1607 }
1608 };
1609
1610 push(@Title_words, $Parts[$i]);
1611 last if $i == 0; # necessary test
1612
1613 last if ($Parts[$i-1] =~ /et\s+al$/i);
1614 last if ($Parts[$i-1] =~ /^\s*\d+$/);
1615
1616 @Words = split(/\s+/, $Parts[$i-1]);
1617 # stop if more than 4 words in $Parts[$i-1],
1618 # i.e. $Parts[$i-1] seems to contain article title,
1619 # not the journal name. However, be aware of:
1620 # "... method for propagating interfaces J. Comput. Phys."
1621 # next if (scalar(@Words) <= 2 and
1622 next if (scalar(@Words) <= 2 and $Parts[$i-1] !~ /^\d/);
1623
1624 if (scalar(@Words) <= 4 and
1625 $Parts[$i-1] =~ /^([A-Z][a-z]*\s+){0,3}[A-Z][a-z]*$/){
1626 next
1627 };
1628
1629 my $w = pop(@Words);
1630 # if ($w =~ /^[A-Z]$/ or $w =~ /^[A-Z][a-z]+$/) {
1631 if ($w =~ /^J$/ or $w =~ /^[A-Z][a-z]+$/) {
1632 push(@Title_words, $w)
1633 };
1634
1635 last
1636 };
1637 if (scalar(@Title_words) == 1) {
1638 $cite->{'title'} = $Title_words[0]
1639 }
1640 else {
1641 my @Title_words_real = reverse(@Title_words);
1642 $cite->{'title'} = join('.', @Title_words_real);
1643 };
1644
1645 $cite->{'title'} = "$cite->{'title'}\." if ($end_dot == 1);
1646
1647 # normalise it
1648 $cite->{'title'} = normalise_journal($cite->{'title'});
1649 return 1
1650 };
1651
1652
1653
1654 sub full_name {
1655 my $Text = shift;
1656
1657 $Text =~ s/(^|s*)Jr[. ]//i;
1658
1659 return 1 if ($Text =~ /^\s*et al\s*$/i);
1660
1661 return 0 if ($Text =~/^in /i);
1662 return 0 if ($Text !~ /[A-Z]/); # no upper case letter
1663 return 0 if ($Text =~ /\d+/); # $Text contains title.
1664 return 0 if ($Text =~ / (e-print|archive)s? /i);
1665 return 0 if ($Text =~ /\b(Collaboration|Review)\b/i);
1666
1667 my $wCount = word_count($Text);
1668 return 0 if $wCount > 4;
1669
1670 # "van Albada" or "van den Bergh" (surname only)
1671 return 0 if ($Text =~ /^((von|van|de|den|der)\s+)+\S\S+\s*$/i);
1672 # "van Buren D"
1673 return 1 if ($Text =~ /^(von|van|de|den|der)\s+\S\S+\s+([a-z]+\s*)+$/i);
1674 # (journal name)
1675 return 0 if ($Text =~ /\b(Phy\.|Physics|Journal|The)\b/i);
1676 # "J. Mod. Phys. D"; "Prog.Theor.Phys."
1677 return 0 if ($Text =~ /^([a-z]+\.\s*)+[a-z]?\s*$/i);
1678 # "Phys Rev A"
1679 # return 0 if ($Text =~ /^([a-z][a-z]+(\.| )){2,}[a-z]\.?\s*$/i);
1680 my @Abbr = ();
1681 # "Class. Quantum Grav."
1682 return 0 if (@Abbr = ($Text =~ /\S\S+?\./g) and
1683 scalar(@Abbr) >1);
1684 # "Nuovo Cim. B 44, 1 (1966)."
1685 return 0 if ($Text =~ /\w\w\w+\./);
1686
1687 # 'W. B. Burton', 'Burton W. B.', 'W B Burton', etc.
1688 if (has_surname($Text) and
1689 has_initials($Text) and
1690 $wCount >= 1 and
1691 $wCount < 5 ) {
1692 return 1
1693 };
1694
1695 # 'Vivek Agrawal', 'Liu Xin' types; hard to distinguish
1696 # surname/firstname.
1697 if ($wCount >= 2 and
1698 $wCount <= 3 and
1699 no_initials($Text)) {
1700 return 1
1701 };
1702
1703 return 0
1704 };
1705
1706 sub no_initials {
1707 my $Text = shift;
1708
1709 # do not count 'Jr.'
1710 $Text =~ s/(\W)Jr\.?\s*$/$1/i;
1711 return 0 if ($Text =~ /(^| )[a-z]\./i);
1712 return 0 if ($Text =~ /(^| )[a-z]( |$)/i);
1713
1714 return 1;
1715 };
1716
1717 sub only_initials {
1718 my $Text = shift;
1719
1720 return 0 if ($Text =~ /^[a-z]{2,} /i);
1721 return 0 if ($Text =~ /\.?\s*[a-z][a-z]+$/i);
1722
1723 my @Words = split(/[\.\s]/, $Text);
1724 my $Word;
1725 foreach $Word (@Words) { return 0 if (length($Word) >= 2)};
1726
1727 return 1
1728 };
1729
1730 sub is_surname {
1731 my ($Text) = @_;
1732 $Text =~ s/ Jr\W+$//i;
1733
1734 return 0 if ($Text =~ / (e-print|archive)s? /i);
1735 return 0 if ($Text =~ /\bCollaboration\b/i);
1736
1737 return 1 if ($Text =~ /^(\s*[a-z][\-'a-z]+){1,3}$/i);
1738 # return 1 if ($Text =~ /^\s*[a-z]+[\-'a-z]+\s*$/i);
1739
1740 return 0
1741 }
1742
1743 sub has_surname {
1744 my $Text = unidecode(shift);
1745
1746 return 0 if ($Text =~ /\d+/);
1747 return 1 if ($Text =~ /^[a-z]{2,}[\s\-\']/i);
1748 # return 1 if ($Text =~ /[a-z]{2,}$/i);
1749 return 1 if ($Text =~ /[\-\'\s.][a-z][a-z]+(\s+Jr\.?)?\s*$/i);
1750 return 0
1751 }
1752
1753 sub has_initials {
1754 my $Text = unidecode(shift);
1755
1756 return 0 if ($Text =~ /\d+/);
1757 return 1 if ($Text =~ /^\s*[']?\s*[A-Z](\s|\.|$)/);
1758 return 1 if ($Text =~ /(^|\s|\.)[a-z](\s|\.|$)/i);
1759
1760 return 0
1761 }
1762
1763 # mainly used to count 'words' in author names
1764 sub word_count {
1765 my ($Text) = @_;
1766
1767 #$Text =~ s/^[\s.]+//;
1768 #my @Words = split(/[\s.]+/, $Text);
1769 # return scalar(@Words);
1770
1771 $Text =~ s/ (von|van|de|den|der) //g;
1772 $Text =~ s/^\s+//;
1773 $Text =~ s/\s+$//;
1774 my @Words_all = split(/\s+/, $Text);
1775 # ignore initials in names.
1776 # e.g. "C.A.R. Sa de Melo" is a name
1777 my @Words;
1778 my $W;
1779 while (@Words_all) {
1780 $W = shift @Words_all;
1781 push(@Words, $W) if ($W !~ /^[a-z]\.?$/i);
1782 };
1783 return scalar(@Words);
1784 };
1785 #
1786 # Normalisation utilities
1787 #
1788 sub normalisation_old {
1789 die;
1790 my($Text) = @_;
1791 # replace embedded '\n' with ' '
1792 $Text =~ s/^\s+//s;
1793 $Text =~ s/\s+$//s;
1794 while ($Text =~ /.+?\n.+?/sg) {
1795 $Text =~ s/(.+?)\n(.+?)/$1 $2/s
1796 };
1797 $Text =~ s/\s*-\s*/-/g; # remove space around '-'
1798 $Text =~ s/\s*'\s*/'/g; # remove space around '
1799 $Text =~ s/\s*:\s*/:/g; # remove space around :
1800 $Text =~ s/\(\s+/\(/g; # ( 1998) ==> (1998)
1801 $Text =~ s/\s+\)/\)/g; # (1998 ) ==> (1998)
1802 while ($Text =~/--/g) {$Text =~ s/--/-/}; # use single '-'.
1803 $Text =~ s/~//g; # remove '~' (e.g. C.~B.~Hanna)
1804 $Text =~ s/\s+/ /g; # use single space;
1805 $Text =~ s/[,;\s]+$//; # remove last ',;\s' on a line
1806 # 'Nr.' caused error in 'find_jnl_name', i.e. it became as
1807 # 'journal name' if not removed. (see: arXiv:quant-ph/9905016)
1808 $Text =~ s/([,;])\s*Nr\.\s*(\d+[,;])/$1$2/i;
1809 # "[12] For example, R. Machleidt, ...Phys. Rep. 149, 1 (1987)
1810 $Text =~ s/^([^a-z]+)for example\W+/$1/i;
1811 # '[18] *** G. Do Dang, ... (arXiv:nucl-th/9911081)
1812 $Text =~ s/\*+//g;
1813 # Phys. Rev. D56 => Phys. Rev. D. 56
1814 $Text =~ s/phys.{1,6}rev.{1,6}([a-z])(\d+)/Phys. Rev. $1 $2/ig;
1815 return $Text;
1816 };
1817
1818 sub normalise_html_old {
1819 die;
1820 my($Text) = @_;
1821
1822 # remove <BR> tag
1823 $Text =~ s/<BR>//ig;
1824 $Text =~ s/&(\w)acute[;,]/$1/g; # a ' on top of (\w)
1825 $Text =~ s/&(\w)cedil[;,]/$1/g; # a 'tail' under (\w), e.g Francios
1826 $Text =~ s/&(\w)grave[;,]/$1/g; # a ` on top of (\w)
1827 $Text =~ s/&(\w)tilde[;,]/$1/g;
1828 $Text =~ s/&(\w)uml[;,]/$1e/g; # a '..' on top of (\w)
1829 $Text =~ s/&(\w)slash[;,]/$1/g;
1830 #$Text =~ s/&#-88;(\w)/$1/g; # as &(\w)uml (see astro-ph/9811179)
1831 $Text =~ s/&#-\d+;\s*(\w)/$1/g;
1832 $Text =~ s/&szlig[;,]/ss/g;
1833 $Text =~ s/&amp[;,]/ and /g;
1834 $Text =~ s/&#20;\s*(\w)/$1/g; # a ~ on top of (\w)
1835 $Text =~ s/\/?i&gt;//g; # cogprints
1836 $Text =~ s/&[a-z]+;//g; # otherwise ';' cause ref line break.
1837 $Text =~ s/&#\d+;//g; # e.g. '&#21' in 'hep-th/0001001 [99]'.
1838 $Text =~ s/\\"(\w)/$1e/g; # G\"unter => Gueter
1839
1840 $Text =~ s/\^//g; # remove ^
1841 $Text =~ s/([A-Z])\s*&\s*([A-Z])/$1 and $2/g; # replace '&' with 'and'
1842 # remove HTML markups (<b></b><i></i> etc.)
1843 $Text =~ s/<[a-z\/]{1,3}>//ig;
1844 return $Text
1845 };
1846
1847
1848 sub normalise_name {
1849 my($Text) = @_;
1850 my $Suffix = '';
1851 $Text =~ s/~//; # remove typo
1852 # Jr.
1853 if ($Text =~ s/[, \.]+(Jr|Sr|Snr)\.?\s*$//i){
1854 $Suffix = $1
1855 }
1856 elsif ($Text =~ s/([, \.]+)(Jr|Sr|Snr)[. ]/$1/i){
1857 $Suffix = $2
1858 };
1859
1860 # van der Buren D => D van der Buren"
1861 if ($Text =~ /^\s*(((van|von|de|den|der)\s+)+)(\S\S+)\s+(.+)/i) {
1862 $Text = "$5 $1 $4"
1863 };
1864 $Text =~ s/\s+/ /g; # single space
1865 $Text =~ s/^\W+//;
1866 $Text =~ s/\s+$//;
1867 # "A. Smith" => "A.Smith"
1868 $Text =~ s/(\w)\.\s+/\U$1\./ig;
1869 # Ghisellini G. A. ==> G.A. Ghisellini
1870 # Konenkov D. Yu. => D.Yu. Konenkov
1871 if ($Text =~ /^([^\s.]{2,})\s+(([A-Z][\w]?\W+)*)([A-Z][\w]?)\W*$/) {
1872 $Text = "$2$4 $1"
1873 };
1874
1875 $Text = "$Text $Suffix" if ($Suffix);
1876 $Text = tdb_normalise_name($Text);
1877 return $Text;
1878 };
1879
1880
1881 # Based on Tim's Authors::splitauthors and Authors::_cmonauthor();
1882 # This subroutine is called simply because we want the author names
1883 # to be transformed to a same style used by Tim's programs. Otherwise
1884 # a join on author names in Publication and Reference tables will
1885 # miss a lot of targets.
1886 sub tdb_normalise_name{
1887 my $author = shift;
1888
1889 # Strip any brackets
1890 $author =~ s/\s*\([^\)]*\)\s*//g;
1891 # Get rid of any dashes (except for dashes like Hu-Su)
1892 $author =~ s/(\W)-/$1/g;
1893 # Remove any "the"s, e.g. The OPAL Collaboration
1894 $author =~ s/\bthe\s+//ig;
1895 # Sort out Jr/Jr.
1896 $author =~ s/,?\sJr\.?/_Jr/ig;
1897
1898 $author =~ s/[\{\}]//g; # Remove any specialisations
1899 $author =~ s/\\.//g; # Remove any escapes
1900 # Convert Convert Hawking S. to S.Hawking (already done - zj)
1901 # ($author =~ /(\w\w+)\s+([\.\w\s]+\.)$/) && ($author = $2.$1);
1902 $author =~ s/\.\s/\./g; # Convert S.W. Hawking to S.W.Hawking
1903 $author =~ s/([A-Z])\s/$1\./g; # Convert S W Hawking to S.W.Hawking
1904 # Can't handle case reliably in international character sets
1905 # $author = lc($author);
1906 # $author =~ s/\b(\w)/\U$1/g;
1907 # Convert STEPHEN_HAWKING to Stephen_Hawking
1908 $author =~ s/\s/_/g; # Convert Stephen W.Hawking to Stephen_W.Hawking
1909 $author =~ s/\.\.+/\./g; # Remove double dots
1910 return $author;
1911 }
1912
1913 sub normalise_date {
1914 my($Text) = @_;
1915
1916 # 12-14 Dec.
1917 $Text =~ s/[^\w\/][0-3][0-9]?[a-z]*?(\s*\-\s*[0-3][0-9]?[a-z]*?)?\s+
1918 (Jan[\.\s]|January\b|Feb[\.\s]|February\b|
1919 Mar[\.\s]|March\b|Apr[\.\s]|April\b|May|
1920 Jun[\.\s]|June\b|Jul[\.\s]|July\b|Aug[\.\s]|August\b|
1921 Sep[\.\s]|September\b|Oct[\.\s]|October\b|
1922 Nov[\.\s]|November\b|Dec[\.\s]|December\b)//xig;
1923
1924 # Dec 12-14
1925 $Text =~ s/(Jan[\.\s]|January\b|Feb[\.\s]|February\b|
1926 Mar[\.\s]|March\b|Apr[\.\s]|April\b|May|
1927 Jun[\.\s]|June\b|Jul[\.\s]|July\b|Aug[\.\s]|August\b|
1928 Sep[\.\s]|September\b|Oct[\.\s]|October\b|
1929 Nov[\.\s]|November\b|Dec[\.\s]|December\b)
1930 [^\w\/]*[0-3][0-9]?[a-z]*?(\s*\-\s*[0-3][0-9]?[a-z]*?)?\b//xig;
1931
1932 return $Text;
1933 };
1934
1935
1936 sub normalise_journal {
1937 my($Text) = @_;
1938 $Text =~ s/^in\s+//i; # "in ..."
1939 $Text =~ s/^(see )?also\s+//i; # "also ...";
1940 $Text =~ s/\s*:\s*/:/g;
1941 $Text =~ s/\s\s/ /g; # single space;
1942 $Text =~ s/\.\s/\./g; # "J. Physics" => "J.Physics"
1943 $Text =~ s/\.\(/\. \(/g;
1944
1945 $Text =~ s/^\W+//;
1946 $Text =~ s/[^\w.]+$//;
1947
1948 # remove anything in brackets at the end.
1949 $Text =~ s/\s*\([^)]+$//; # e.g. R. Ram, J. Phys. (Paris
1950 $Text =~ s/^[^(]+\)\s*//; # e.g. a) R. Ram, J. Phys. 10, 120, 1998
1951
1952 # unify cases
1953 #($Text = lc($Text)) && ($Text =~ s/\b(\w)/\U$1/g);
1954 $Text = uc($Text);
1955 return $Text;
1956 };
1957
1958
1959 sub num_of_figures {
1960 my($Text) = @_;
1961 my($N, @Nlist);
1962 $N = 0;
1963 @Nlist =();
1964
1965 $Text = normalisation($Text);
1966 # e.g. "p. 24-26" regarded as one number.
1967 # ignore 'N = 2' kind of equations, and
1968 # ignore '25th' kinds (e.g. Proc. 25th ICRC).
1969 # ignore 'protein Aquaporin-1 in ...'
1970 # ignore 'hep-th/9901001'
1971 # ignore ' ... 1.55, ...'
1972 while ($Text =~ /(?:^|\b)[a-z]*(\d+)([a-z]*)
1973 (?:-[a-z]*\d+[a-z]*)*
1974 (?:\b|$)/gix) {
1975 next if ($2 =~ /^th$/i);
1976 next if ($' =~ /^\.\d+/);
1977 next if ($` =~ /\d+\.$/);
1978 next if ($` =~ /[=<>\/-]\s*$/);
1979 push(@Nlist, $1);
1980 }
1981 $N = scalar(@Nlist);
1982 return $N
1983 }
1984
1985
1986 sub remove_extra_spc {
1987 my($Text) = @_;
1988 $Text =~ s/^\s+//;
1989 $Text =~ s/\s+$//;
1990 $Text =~ s/\s\s/ /g;
1991 return $Text
1992 };
1993
1994 #
1995 # To assist accessing of the citation meta data.
1996 #
1997 sub srcText {
1998 my $cite = shift;
1999 return $cite->{'text'};
2000 }
2001
2002 sub targetIdentifier {
2003 return $_[0]->{'targetID'};
2004 }
2005
2006 sub targetURL {
2007 return $_[0]->{'targetURL'};
2008 }
2009
2010 sub authors {
2011 return $_[0]->{'authors'};
2012 }
2013
2014 sub list_authors {
2015 my $cite = shift;
2016 return $cite->{'authors'}
2017 }
2018
2019 sub aufull {
2020 return $_[0]->{'aufull'};
2021 }
2022
2023 sub first_author {
2024 my $cite = shift;
2025 return $cite->{'aufull'};
2026 }
2027
2028 sub aulast {
2029 my $cite = shift;
2030 return $cite->{'aulast'};
2031 }
2032
2033 sub aufirst {
2034 my $cite = shift;
2035 return $cite->{'aufirst'};
2036 }
2037
2038 sub auinit {
2039 my $cite = shift;
2040 return $cite->{'auinit'};
2041 }
2042
2043 # journal title
2044 sub title {
2045 my $cite = shift;
2046 return $cite->{'title'};
2047 }
2048
2049 # article title
2050 sub atitle {
2051 my $cite = shift;
2052 return $cite->{'atitle'};
2053 }
2054
2055 sub volume {
2056 my $cite = shift;
2057 return $cite->{'volume'};
2058 }
2059
2060 sub issue {
2061 my $cite = shift;
2062 return $cite->{'issue'};
2063 }
2064
2065 sub supplement {
2066 my $cite = shift;
2067 return $cite->{'supl'};
2068 }
2069
2070 sub year {
2071 my $cite = shift;
2072 return $cite->{'year'};
2073 }
2074
2075 sub startpage {
2076 my $cite = shift;
2077 return $cite->{'spage'};
2078 }
2079
2080 sub endpage {
2081 return $_[0]->{'epage'};
2082 }
2083
2084 sub journal {
2085 my $cite = shift;
2086 return $cite->{'title'};
2087 }
2088
2089 sub featureID {
2090 my $cite = shift;
2091 return $cite->{'featureID'}
2092 }
2093
2094
2095 sub mysql_load_file {
2096 my $cite = shift;
2097
2098 my $tm = localtime;
2099 my ($year,$mon,$mday);
2100 $year = $tm->year + 1900;
2101 $mon = $tm->mon + 1;
2102 $mday = $tm->mday;
2103 my $TimeStamp = $year.'-'.$mon.'-'.$mday;
2104 $cite->{'date'} = $TimeStamp;
2105
2106 print "$cite->{'date'}\t";
2107 print "$cite->{'sourceID'}\t";
2108
2109 ($cite->{'featureID'}) ? print "$cite->{'featureID'}\t"
2110 : print "\\N\t";
2111
2112 ($cite->{'targetID'}) ? print "$cite->{'targetID'}\t"
2113 : print "\\N\t";
2114
2115 ($cite->{refID}) ? print "$cite->{refID}\t"
2116 : print "\\N\t";
2117
2118 ($cite->{'targetURL'}) ? print "$cite->{'targetURL'}\t"
2119 : print "\\N\t";
2120
2121 ($cite->{'text'}) ? print "$cite->{'text'}\t"
2122 : print "\\N\t";
2123
2124 ($cite->{'aufull'}) ? print "$cite->{'aufull'}\t"
2125 : print "\\N\t";
2126
2127 ($cite->{'aulast'}) ? print "$cite->{'aulast'}\t"
2128 : print "\\N\t";
2129
2130 ($cite->{'aufirst'}) ? print "$cite->{'aufirst'}\t"
2131 : print "\\N\t";
2132
2133 ($cite->{'auinit'}) ? print "$cite->{'auinit'}\t"
2134 : print "\\N\t";
2135
2136 ($cite->{'atitle'}) ? print "$cite->{'atitle'}\t"
2137 : print "\\N\t";
2138
2139 ($cite->{'title'}) ? print "$cite->{'title'}\t"
2140 : print "\\N\t";
2141
2142 ($cite->{'volume'}) ? print "$cite->{'volume'}\t"
2143 : print "\\N\t";
2144
2145 ($cite->{'issue'}) ? print "$cite->{'issue'}\t"
2146 : print "\\N\t";
2147
2148 ($cite->{'supl'}) ? print "$cite->{'supl'}\t"
2149 : print "\\N\t";
2150
2151 ($cite->{'spage'}) ? print "$cite->{'spage'}\t"
2152 : print "\\N\t";
2153
2154 ($cite->{'year'}) ? print "$cite->{'year'}"
2155 : print "\\N";
2156 print "\n";
2157 }
2158
2159 sub print_out {
2160 my $cite = shift;
2161 return if (!defined($cite->{'text'}));
2162 print '-'x70,"\n";
2163 print "$cite->{'text'} \n", '-'x70, "\n";
2164 print "sourceID: \t$cite->{'sourceID'}\n" if ($cite->{'sourceID'});
2165 print "Authors: \t$cite->{'authors'}\n" if ($cite->{'authors'});
2166 print "First Author: \t$cite->{'aufull'}\n" if ($cite->{'aufull'});
2167 print "Article title:\t$cite->{'atitle'}\n" if ($cite->{'atitle'});
2168 print "Journal: \t$cite->{'title'}\n" if ($cite->{'title'});
2169 print "Volume: \t$cite->{'volume'}\n" if ($cite->{'volume'});
2170 print "Issue: \t$cite->{'issue'} \n" if ($cite->{'issue'});
2171 print "Supplement: \t$cite->{'supl'} \n" if ($cite->{'supl'});
2172 print "Start Page: \t$cite->{'spage'}\n" if ($cite->{'spage'});
2173 print "Year: \t\t$cite->{'year'}\n" if ($cite->{'year'});
2174 print "targetURL: \t$cite->{'targetURL'}\n" if ($cite->{'targetURL'});
2175 print "featureID: \t$cite->{'featureID'}\n" if ($cite->{'featureID'});
2176 print "targetID: \t$cite->{'targetID'}\n" if ($cite->{'targetID'});
2177 };
2178
2179 1;
2180