Skip to content

Commit

Permalink
#84 month fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 18, 2024
1 parent 99623ec commit 6a18ebf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
31 changes: 30 additions & 1 deletion bibcop.pl
Expand Up @@ -40,7 +40,7 @@ package bibcop;
'article' => ['doi', 'year', 'title', 'author', 'journal', 'volume', 'number', 'month?', 'publisher?', 'pages?'],
'inproceedings' => ['doi', 'booktitle', 'title', 'author', 'year', 'pages?', 'month?', 'organization?', 'volume?'],
'book' => ['title', 'author', 'year', 'publisher', 'doi?'],
'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'month?', 'publisher?', 'organization?', 'doi?', 'howpublished?', 'note?'],
'misc' => ['title', 'author', 'year', 'eprint?', 'archiveprefix?', 'primaryclass?', 'month?', 'publisher?', 'organization?', 'doi?', 'howpublished?', 'note?', 'pages?', 'number?', 'volume?'],
);

# See https://research.arizona.edu/faq/what-do-you-mean-when-you-say-use-title-case-proposalproject-titles
Expand Down Expand Up @@ -601,6 +601,35 @@ sub fix_number {
return $value;
}

sub fix_month {
my ($value) = @_;
my %months = (
'1' => 'jan',
'2' => 'feb',
'3' => 'mar',
'4' => 'apr',
'5' => 'may',
'6' => 'jun',
'7' => 'jul',
'8' => 'aug',
'9' => 'sep',
'10' => 'oct',
'11' => 'nov',
'12' => 'dec',
);
$value =~ s/^0+//g;
if ($value =~ /^11|12|[0-9]$/) {
$value = $months{$value};
} else {
my %rev = reverse %months;
my $lc = substr(lc($value), 0, 3);
if (exists $rev{$lc}) {
$value = $lc;
}
}
return $value;
}

sub fix_capitalization {
my ($value) = @_;
my @words = split(/\s+/, $value);
Expand Down
7 changes: 7 additions & 0 deletions perl-tests/fixing.pl
Expand Up @@ -72,6 +72,13 @@ package bibcop;
fixes('number', '007', '7');
fixes('number', '16', '16');

fixes('month', '02', 'feb');
fixes('month', 'January', 'jan');
fixes('month', 'Dec', 'dec');
fixes('month', '9', 'sep');
fixes('month', 'mar', 'mar');
fixes('month', 'something', 'something');

sub fixes {
my ($tag, $before, $expected) = @_;
my $fixer = "fix_$tag";
Expand Down

0 comments on commit 6a18ebf

Please sign in to comment.