| 1 | package Biblio::Citation::Parser::Standard; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Biblio::Citation::Parser::Standard; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | @ISA = ("Exporter", "Biblio::Citation::Parser"); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use Biblio::Citation::Parser::Templates; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | our @EXPORT_OK = ( 'parse', 'new' ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | B<Biblio::Citation::Parser::Standard> - citation parsing functionality | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | use Biblio::Citation::Parser::Standard; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # Parse a simple reference | ||||||||||||||||||||||||||||||||||||||||||
| 48 | $parser = new Biblio::Citation::Parser::Standard; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | $metadata = $parser->parse("M. Jewell (2004) Citation Parsing for Beginners. Journal of Madeup References 4(3)."); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | print "The title of this article is ".$metadata->{atitle}."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | Biblio::Citation::Parser::Standard uses a relatively simple template matching | ||||||||||||||||||||||||||||||||||||||||||
| 55 | technique to extract metadata from citations. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | The Templates.pm module currently provides almost 400 templates, with | ||||||||||||||||||||||||||||||||||||||||||
| 58 | more being added regularly, and the parser returns the metadata in a | ||||||||||||||||||||||||||||||||||||||||||
| 59 | form that is easily massaged into OpenURLs (see the Biblio::OpenURL | ||||||||||||||||||||||||||||||||||||||||||
| 60 | module for an even easier way). | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my %factors = | |||||||||||||||||||||||||||||||||||||||||
| 66 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 67 | "_AUFIRST_" => 0.6, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | "_AULAST_" => 0.6, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | "_ISSN_" => 0.95, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | "_AUTHORS_" => 0.65, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | "_EDITOR_" => 0.6, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | "_DATE_" => 0.95, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | "_YEAR_" => 0.8, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | "_SUBTITLE_" => 0.6, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | "_TITLE_" => 0.6, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | "_UCTITLE_" => 0.7, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | "_CAPTITLE_" => 0.7, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | "_PUBLICATION_" => 0.65, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | "_PUBLISHER_" => 0.65, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | "_PUBLOC_" => 0.65, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | "_UCPUBLICATION_" => 0.74, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | "_CAPPUBLICATION_" => 0.7, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | "_CHAPTER_" => 0.8, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | "_VOLUME_" => 0.8, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | "_ISSUE_" => 0.8, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | "_PAGES_" => 0.9, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | "_ANY_" => 0.05, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | "_ISBN_" => 0.95, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | "_ISSN_" => 0.95, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | "_SPAGE_" => 0.8, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | "_EPAGE_" => 0.8, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | "_URL_" => 0.9, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =item $parser = Biblio::Citation::Parser::Standard-E<gt>new() | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | The new() method creates a new parser. | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | return bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =item $reliability = Biblio::Citation::Parser::Standard::get_reliability($template) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | The get_reliability method returns a value that acts as an indicator | ||||||||||||||||||||||||||||||||||||||||||
| 119 | of the likelihood of a template matching correctly. Fields such as | ||||||||||||||||||||||||||||||||||||||||||
| 120 | page ranges, URLs, etc, have high likelihoods (as they follow rigorous | ||||||||||||||||||||||||||||||||||||||||||
| 121 | patterns), whereas titles, publications, etc have lower likelihoods. | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | The method takes a template as a parameter, but you shouldn't really | ||||||||||||||||||||||||||||||||||||||||||
| 124 | need to use this method much. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | sub get_reliability | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_reliability: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my( $template ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | my $reliability = 0; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | foreach(keys %factors) | |||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 200 | ▶ | if ($template =~ /$_/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 30 | ▶ | while($template =~ /$_/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 30 | $reliability += $factors{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 30 | $template =~ s/$_//; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | return $reliability; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | =item $concreteness = Biblio::Citation::Parser::Standard::get_concreteness($template) | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | As with the get_reliability() method, get_concreteness() takes | ||||||||||||||||||||||||||||||||||||||||||
| 151 | a template as a parameter, and returns a numeric indicator. In | ||||||||||||||||||||||||||||||||||||||||||
| 152 | this case, it is the number of non-field characters in the template. | ||||||||||||||||||||||||||||||||||||||||||
| 153 | The more 'concrete' a template, the higher the probability that | ||||||||||||||||||||||||||||||||||||||||||
| 154 | it will match well. For example, '_PUBLICATION_ Vol. _VOLUME_' is | ||||||||||||||||||||||||||||||||||||||||||
| 155 | a better match than '_PUBLICATION_ _VOLUME_', as _PUBLICATION_ is | ||||||||||||||||||||||||||||||||||||||||||
| 156 | likely to subsume 'Vol.' in the second case. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | sub get_concreteness | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_concreteness: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | my( $template ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 8 | my $concreteness = 0; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | foreach(keys %factors) | |||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 200 | $template =~ s/$_//g; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | return length($template); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | =item $string = Biblio::Citation::Parser::Standard::strip_spaces(@strings) | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | This is a helper function to remove spaces from all elements | ||||||||||||||||||||||||||||||||||||||||||
| 176 | of an array. | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | sub strip_spaces | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_spaces: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | my(@bits) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | foreach(@bits) { s/^[[:space:]]*(.+)[[:space:]]*$/$1/;} | |||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | return @bits; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =item $templates = Biblio::Citation::Parser::Standard::get_templates() | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Returns the current template list from the Biblio::Citation::Parser::Templates | ||||||||||||||||||||||||||||||||||||||||||
| 192 | module. Useful for giving status lists. | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | sub get_templates | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_templates: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return $Biblio::Citation::Parser::Templates::templates; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | =item @authors = Biblio::Citation::Parser::Standard::handle_authors($string) | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | This (rather large) function handles the author fields of a reference. | ||||||||||||||||||||||||||||||||||||||||||
| 206 | It is not all-inclusive yet, but it is usably accurate. It can handle | ||||||||||||||||||||||||||||||||||||||||||
| 207 | author lists that are separated by semicolons, commas, and a few other | ||||||||||||||||||||||||||||||||||||||||||
| 208 | delimiters, as well as &, and, and 'et al'. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | The method takes an author string as a parameter, and returns an array | ||||||||||||||||||||||||||||||||||||||||||
| 211 | of extracted information in the format '{family => $family, given => | ||||||||||||||||||||||||||||||||||||||||||
| 212 | $given}'. | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | sub handle_authors | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_authors: called CC=24 SCAR=55.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | my($authstr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | my @authsout = (); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | $authstr =~ s/\bet al\b//; | |||||||||||||||||||||||||||||||||||||||||
| 222 | # Handle semicolon lists | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | if ($authstr =~ /;/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my @auths = split /[[:space:]]*;[[:space:]]*/, $authstr; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | foreach(@auths) | |||||||||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my @bits = split /[,[:space:]]+/; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | @bits = strip_spaces(@bits); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | push @authsout, {family => $bits[0], given => $bits[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | elsif ($authstr =~ /^[[:upper:]\.]+[[:space:]]+[[:alnum:]]/) | ||||||||||||||||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my @bits = split /[[:space:]]+/, $authstr; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | @bits = strip_spaces(@bits); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $fam = 0; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my($family, $given); | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | foreach(@bits) | |||||||||||||||||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | next if ($_ eq "and" || $_ eq "&" || /^[[:space:]]*$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$_ eq "and" or $_ eq "&" or /^[[:space:]]*$/
$_ eq "and" or $_ eq "&"
MC/DC0%0/3
$_ eq "and" or $_ eq "&" or /^[[:space:]]*$/
$_ eq "and"
$_ eq "&"
/^[[:space:]]*$/
Truth table0%0/4
A or B or C
A= $_ eq "and"B= $_ eq "&"C= /^[[:space:]]*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | s/,//g; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ($fam) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $family = $_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | push @authsout, {family => $family, given => $given}; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $fam = 0; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | else | ||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $given = $_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $fam = 1; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | elsif ($authstr =~ /^.+[[:space:]]+[[:upper:]\.]+/) | ||||||||||||||||||||||||||||||||||||||||||
| 257 | { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # Foo AJ, Bar PJ | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | my $fam = 1; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | my $family = ""; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | my $given = ""; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | my @bits = split /[[:space:]]+/, $authstr; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | @bits = strip_spaces(@bits); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | foreach(@bits) | |||||||||||||||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | s/[,;\.]//g; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | s/\bet al\b//g; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | s/\band\b//; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | s/\b&\b//; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | ▶ | next if /^[[:space:]]*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | ▶ | if ($fam == 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | $family = $_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | $fam = 0; | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | else | ||||||||||||||||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | $given = $_; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | $fam = 1; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | push @authsout, {family => $family, given => $given}; | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | ▶ | elsif ($authstr =~ /^.+,[[:space:]]*.+/ || $authstr =~ /.+\band\b.+/) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$authstr =~ /^.+,[[:space:]]*.+/ or $authstr =~ /.+\band\b.+/
MC/DC0%0/2
$authstr =~ /^.+,[[:space:]]*.+/ or $authstr =~ /.+\band\b.+/
$authstr =~ /^.+,[[:space:]]*.+/
$authstr =~ /.+\band\b.+/
Truth table0%0/3
A or B
A= $authstr =~ /^.+,[[:space:]]*.+/B= $authstr =~ /.+\band\b.+/
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $fam = 1; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $family = ""; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $given = ""; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my @bits = split /[[:space:]]*,|\band\b|&[[:space:]]*/, $authstr; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | @bits = strip_spaces(@bits); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | foreach(@bits) | |||||||||||||||||||||||||||||||||||||||||
| 293 | { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | next if /^[[:space:]]*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ($fam) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $family = $_; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $fam = 0; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | else | ||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $given = $_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | push @authsout, {family => $family, given => $given}; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $fam = 1; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | elsif ($authstr =~ /^[[:alpha:][:space:]]+$/) | ||||||||||||||||||||||||||||||||||||||||||
| 309 | { | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $authstr =~ /^([[:alpha:]]+)[[:space:]]*([[:alpha:]]*)$/; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $given = ""; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $family = ""; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if (defined $1 && defined $2) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $1 and defined $2
MC/DC0%0/2
defined $1 and defined $2
defined $1
defined $2
Truth table0%0/3
A and B
A= defined $1B= defined $2
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | { | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $given = $1; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $family = $2; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if (!defined $2 || $2 eq "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $2 or $2 eq ""
MC/DC0%0/2
not defined $2 or $2 eq ""
not defined $2
$2 eq ""
Truth table0%0/3
not(A) or B
A= not defined $2B= $2 eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $family = $1; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $given = ""; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | push @authsout, {family => $family, given => $given}; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | elsif( $authstr =~ /[[:word:]]+[[:space:]]+[[:word:]]?[[:space:]]*[[:word:]]+/) | ||||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my @bits = split /[[:space:]]+/, $authstr; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $rest = $authstr; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $rest =~ s/$bits[-1]//; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | push @authsout, {family => $bits[-1], given => $rest}; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | else | ||||||||||||||||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | return @authsout; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | =item %metadata = $parser-E<gt>xtract_metadata($reference) | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | This is the key method in the Standard module, although it is not actually | ||||||||||||||||||||||||||||||||||||||||||
| 344 | called directly by users (the 'parse' method provides a wrapper). It takes | ||||||||||||||||||||||||||||||||||||||||||
| 345 | a reference, and returns a hashtable representing extracted metadata. | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | A regular expression map is present in this method to transform '_AUFIRST_', | ||||||||||||||||||||||||||||||||||||||||||
| 348 | '_ISSN_', etc, into expressions that should match them. The method then | ||||||||||||||||||||||||||||||||||||||||||
| 349 | finds the template which best matches the reference, picking the result that | ||||||||||||||||||||||||||||||||||||||||||
| 350 | has the highest concreteness and reliability (see above), and returns the | ||||||||||||||||||||||||||||||||||||||||||
| 351 | fields in the hashtable. It also creates the marked-up version, that is | ||||||||||||||||||||||||||||||||||||||||||
| 352 | useful for further formatting. | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | sub extract_metadata | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_metadata: called CC=27 SCAR=36.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | my($self, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | # Skip to the first Alpha char | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | if ($ref !~ /^[[:digit:]]-X\.]+$/) { $ref =~ s/^[^[:alpha:]]+//; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | $ref =~ s/[[:space:]\*]+$//; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | $ref =~ s/[[:space:]]{2}[[:space:]]+/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | $ref =~ s/^[[:space:]\*]*(.+)[[:space:]\*]*$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | my %metaout = (); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | $metaout{ref} = $ref; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | $metaout{id} = []; | |||||||||||||||||||||||||||||||||||||||||
| 368 | # Pull out doi addresses | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | ▶ | if ($ref =~ s/doi:(.+)\b//) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | push @{$metaout{id}}, "doi:$1"; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | ▶ | if ($ref =~ s/((astro-ph|cond-mat|gr-qc|hep-ex|hep-lat|hep-ph|hep-th|math-th|nucl-ex|nucl-th|physics|quant-ph|math|nlin|cs)\/\d+\b)//) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | push @{$metaout{id}}, "arxiv:$1"; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | my @specific_pubs = | |||||||||||||||||||||||||||||||||||||||||
| 378 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 379 | # Put any specific publications in here | ||||||||||||||||||||||||||||||||||||||||||
| 380 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | my $spec_pubs = ""; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | if (scalar @specific_pubs > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $spec_pubs = join("|", @specific_pubs); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $spec_pubs = "|".$spec_pubs; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | my $initial_match = "(?:\\b[[:alpha:]]\\.|\\b[[:alpha:]]\\b)"; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | my $name_match = "(?:(?:[[:alpha:],;&-]+)\\b)"; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | my $conjs = "(?:\\s+und\\s+|\\s+band\\s+|\\s|,|&|;)"; | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | my %matches = | |||||||||||||||||||||||||||||||||||||||||
| 394 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 395 | "_AUFIRST_" => "([[:alpha:]\.]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 396 | "_AULAST_" => "([[:alpha:]-]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 397 | "_ISSN_" => "([[:digit:]-]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 398 | "_AUTHORS_" => "((?:$initial_match|$name_match|$conjs)+?)", | ||||||||||||||||||||||||||||||||||||||||||
| 399 | "_DATE_" => "([[:digit:]]{2}/[[:digit:]]{2}/[[:digit]]{2})", | ||||||||||||||||||||||||||||||||||||||||||
| 400 | "_YEAR_" => "([[:digit:]]{4})", | ||||||||||||||||||||||||||||||||||||||||||
| 401 | "_TITLE_" => "(.+?[a-zA-Z]+.+?)", | ||||||||||||||||||||||||||||||||||||||||||
| 402 | "_SUBTITLE_" => "(.+)", | ||||||||||||||||||||||||||||||||||||||||||
| 403 | "_CHAPTER_" => "([[:digit:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 404 | "_UCTITLE_" => "([^[:lower:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 405 | "_CAPTITLE_" => "([[:upper:]][^[:upper:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 406 | "_PUBLICATION_" => "([^0-9\(\);\"']{4,}$spec_pubs)", | ||||||||||||||||||||||||||||||||||||||||||
| 407 | "_PUBLISHER_" => "(.+)", | ||||||||||||||||||||||||||||||||||||||||||
| 408 | "_PUBLOC_" => "(.+)", | ||||||||||||||||||||||||||||||||||||||||||
| 409 | "_EDITOR_" => "([[:alpha:]\\.,;\\s&-]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 410 | "_UCPUBLICATION_" => "([^[:lower:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 411 | "_CAPPUBLICATION_" => "([[:upper:]][^[:upper:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 412 | "_VOLUME_" => "([[:digit:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 413 | "_ISSUE_" => "([[:digit:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 414 | "_PAGES_" => "([[:digit:]]+-{1,2}[[:digit:]]+?)", | ||||||||||||||||||||||||||||||||||||||||||
| 415 | "_ANY_" => "(.+?)", | ||||||||||||||||||||||||||||||||||||||||||
| 416 | "_ISBN_" => "([[:digit:]X-]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 417 | "_ISSN_" => "([[:digit:]X-]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 418 | "_SPAGE_" => "([[:digit:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 419 | "_EPAGE_" => "([[:digit:]]+)", | ||||||||||||||||||||||||||||||||||||||||||
| 420 | "_URL_" => "(((http(s?):\\/\\/(www\\.)?)|(\\bwww\\.)|(ftp:\\/\\/(ftp\\.)?))([-\\w\\.:\\/\\s]+)(\\/|\\.\\S+|#\\w+))", | ||||||||||||||||||||||||||||||||||||||||||
| 421 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | my(@newtemplates) = (); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | foreach my $template (@$Biblio::Citation::Parser::Templates::templates) | |||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 385 | $_ = $template; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 385 | s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 385 | s/\(/\\\(/g; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 385 | s/\)/\\\)/g; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 385 | s/\[/\\\[/g; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 385 | s/\]/\\\]/g; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 385 | s/\./\\\./g; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 385 | s/ /\[\[:space:\]\]+/g; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 385 | s/\?/\\\?/g; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 385 | foreach my $key (keys %matches) | |||||||||||||||||||||||||||||||||||||||||
| 437 | { | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 9625 | s/$key/$matches{$key}/g; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 385 | $_ .= "[.]?"; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 385 | push @newtemplates,$_; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | my @vars = (); | |||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my @matchedvars = (); | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | my $curr_conc = 0; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | my $curr_rel = 0; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | my $max_conc = 0; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | my $max_rel = 0; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | my $best_match = ""; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | my $best_orig = ""; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | foreach my $currtemplate (@newtemplates) | |||||||||||||||||||||||||||||||||||||||||
| 454 | { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 385 | my $original = $Biblio::Citation::Parser::Templates::templates->[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 385 | ▶ | if ($ref =~ /^$currtemplate$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 8 | $curr_rel = get_reliability($original); | |||||||||||||||||||||||||||||||||||||||||
| 459 | 8 | $curr_conc = get_concreteness($original); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 8 | ▶ | if ($curr_rel > $max_rel) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 3 | $best_match = $currtemplate; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 3 | $best_orig = $original; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 3 | $max_conc = $curr_conc; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 3 | $max_rel = $curr_rel; | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | ▶ | elsif ($curr_rel == $max_rel && $curr_conc > $max_conc) | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$curr_rel == $max_rel and $curr_conc > $max_conc
MC/DC0%0/2
$curr_rel == $max_rel and $curr_conc > $max_conc
$curr_rel == $max_rel
$curr_conc > $max_conc
Truth table66%2/3
A and B
A= $curr_rel == $max_relB= $curr_conc > $max_conc
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | { | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $best_match = $currtemplate; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $best_orig = $original; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $max_conc = $curr_conc; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | $max_rel = $curr_rel; | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 385 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | $metaout{match} = $best_orig; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | @vars = ($best_orig =~ /_([A-Z]+)_/g); | |||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | @matchedvars = ($ref =~ /^$best_match$/); | |||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | ▶ | if (scalar @matchedvars > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | foreach(@vars) | |||||||||||||||||||||||||||||||||||||||||
| 486 | { | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 6 | $matchedvars[$index] =~ s/^\s*(.+)\s*$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 6 | $metaout{lc $_} = $matchedvars[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 6 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | foreach(keys %metaout) | |||||||||||||||||||||||||||||||||||||||||
| 493 | { | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 9 | ▶ | if (/^uc/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $alt = $_; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $alt =~ s/^uc//; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if (!defined $metaout{$alt} || $metaout{$alt} eq "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $metaout{$alt} or $metaout{$alt} eq ""
MC/DC0%0/2
not defined $metaout{$alt} or $metaout{$alt} eq ""
not defined $metaout{$alt}
$metaout{$alt} eq ""
Truth table0%0/3
not(A) or B
A= not defined $metaout{$alt}B= $metaout{$alt} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $metaout{$alt} = $metaout{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | # Create a marked-up version | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | my $in_ref = $ref; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | my $in_tmp = $best_orig; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | my $in_tmp2 = $best_orig; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | foreach(keys %metaout) | |||||||||||||||||||||||||||||||||||||||||
| 510 | { | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 9 | ▶ | next if (!defined $metaout{$_} || $metaout{$_} eq "" || $_ eq "any"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $metaout{$_} or $metaout{$_} eq "" or $_ eq "any"
not defined $metaout{$_} or $metaout{$_} eq ""
MC/DC0%0/3
not defined $metaout{$_} or $metaout{$_} eq "" or $_ eq "any"
not defined $metaout{$_}
$metaout{$_} eq ""
$_ eq "any"
Truth table25%1/4
not(A) or B or C
A= not defined $metaout{$_}B= $metaout{$_} eq ""C= $_ eq "any"
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 9 | my $toreplace = "_".(uc $_)."_"; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 9 | $in_tmp =~ s/$toreplace/<$_>$metaout{$_}<\/$_>/g; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 9 | $in_tmp2 =~ s/$toreplace/$metaout{$_}/g; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | # Fix any _ANY_s | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | $in_tmp2 =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | $in_tmp2 =~ s/\(/\\\(/g; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | $in_tmp2 =~ s/\)/\\\)/g; | |||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | $in_tmp2 =~ s/\[/\\\[/g; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | $in_tmp2 =~ s/\]/\\\]/g; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | $in_tmp2 =~ s/\./\\\./g; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | $in_tmp2 =~ s/ /\[\[:space:\]\]+/g; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | $in_tmp2 =~ s/\?/\\\?/g; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 1 | $in_tmp2 =~ s/_ANY_/(.+)/g; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | my(@anys) = ($in_ref =~ /$in_tmp2/g); | |||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | foreach(@anys) | |||||||||||||||||||||||||||||||||||||||||
| 530 | { | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | $in_tmp =~ s/_ANY_/<any>$_<\/any>/; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | $metaout{marked} = $in_tmp; | |||||||||||||||||||||||||||||||||||||||||
| 534 | # Map to OpenURL | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | ▶ | if (defined $metaout{authors}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | { | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | $metaout{authors} = [handle_authors($metaout{authors})]; | |||||||||||||||||||||||||||||||||||||||||
| 538 | 1 | $metaout{aulast} = $metaout{authors}[0]->{family}; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | $metaout{aufirst} = $metaout{authors}[0]->{given}; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 1 | ▶ | if (defined $metaout{publisher} && !defined $metaout{publication}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $metaout{"publisher"} and not defined $metaout{"publication"}
MC/DC0%0/2
defined $metaout{"publisher"} and not defined $metaout{"publication"}
defined $metaout{"publisher"}
not defined $metaout{"publication"}
Truth table33%1/3
A and not(B)
A= defined $metaout{"publisher"}B= not defined $metaout{"publication"}
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | { | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $metaout{genre} = "book"; | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 1 | $metaout{atitle} = $metaout{title}; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 1 | $metaout{title} = $metaout{publication}; | |||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | if (defined $metaout{cappublication}) { $metaout{title} = $metaout{cappublication} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | $metaout{date} = $metaout{year}; | |||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | return %metaout; | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | =item $metadata = $parser-E<gt>parse($reference); | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | This method provides a wrapper to the extract_metadata | ||||||||||||||||||||||||||||||||||||||||||
| 558 | function. Simply pass a reference string, and a metadata | ||||||||||||||||||||||||||||||||||||||||||
| 559 | hash is returned. | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | sub parse | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | my($self, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | my $hashout = {$self->extract_metadata($ref)}; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | return $hashout; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | __END__ | ||||||||||||||||||||||||||||||||||||||||||