Skip to content

Commit

Permalink
TTO-184 Rights predictor to 75 years for Canada anonymous works (#136)
Browse files Browse the repository at this point in the history
* TTO-184 Rights predictor to 75 for Canada anonymous works
- Rights predictor for Canada is now sensitive to the is_pub/anonymous/corporate status of a work
  - Use a new constant CANADA_CORPORATE_TERM set to 75 years
  - Pass the is_pub flag to all per-country rights predictors
  - Update tests with a separate author death date vs anonymous/pub date example for Canada
  • Loading branch information
moseshll authored Mar 11, 2024
1 parent fd7f9ca commit fc68ca3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cgi/CRMS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sub new
return $self;
}

our $VERSION = '8.5.24';
our $VERSION = '8.5.25';
sub Version
{
return $VERSION;
Expand Down
19 changes: 13 additions & 6 deletions lib/CRMS/RightsPredictor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use constant {
# Thus, if last source copyright year >= 1996 then the work is GATT-eligible.
GATT_RESTORATION_START => 1996,
COMMONWEALTH_CROWN_COPYRIGHT_TERM => 50,
COMMONWEALTH_STANDARD_TERM => 70
COMMONWEALTH_STANDARD_TERM => 70,
CANADA_CORPORATE_TERM => 75
};

# Sanity check on reviewer-supplied date
Expand Down Expand Up @@ -69,11 +70,13 @@ sub new {
sub last_source_copyright {
my $self = shift;
my $death_or_pub_date = shift || ''; # Reviewer-supplied
my $is_pub = shift; # Treat $death_or_pub_date as pub date for corporate authors
my $is_crown = shift; # Crown copyright
my $reference_year = shift || POSIX::strftime("%Y", localtime); # The "current" year

# Initialize return struct
my $prediction = { death_or_pub_date => $death_or_pub_date,
is_pub => $is_pub,
is_crown => $is_crown,
reference_year => $reference_year,
desc => [],
Expand Down Expand Up @@ -204,30 +207,34 @@ sub predict_last_source_copyright {
return if $prediction->{error};
my $country = $self->{record}->country;
my $predictor = $TERM_PREDICTORS->{$country};
my $term = $predictor->($prediction->{death_or_pub_date}, $prediction->{is_crown});
my $term = $predictor->(
$prediction->{death_or_pub_date},
$prediction->{is_pub},
$prediction->{is_crown}
);
$prediction->{last_source_copyright_year} = $prediction->{death_or_pub_date} + $term;
push @{$prediction->{desc}},
"Last $country © $prediction->{last_source_copyright_year} ($prediction->{death_or_pub_date} + $term-year term)";
}

sub australia_term {
my ($death_or_pub_date, $is_crown) = @_;
my ($death_or_pub_date, undef, $is_crown) = @_;

return COMMONWEALTH_CROWN_COPYRIGHT_TERM if $is_crown;
return 50 if $death_or_pub_date < 1955;
return COMMONWEALTH_STANDARD_TERM;
}

sub canada_term {
my ($death_or_pub_date, $is_crown) = @_;
my ($death_or_pub_date, $is_pub, $is_crown) = @_;

return COMMONWEALTH_CROWN_COPYRIGHT_TERM if $is_crown;
return 50 if $death_or_pub_date < 1972;
return COMMONWEALTH_STANDARD_TERM;
return $is_pub ? CANADA_CORPORATE_TERM : COMMONWEALTH_STANDARD_TERM;
}

sub united_kingdom_term {
my ($death_or_pub_date, $is_crown) = @_;
my ($death_or_pub_date, undef, $is_crown) = @_;

return ($is_crown) ? COMMONWEALTH_CROWN_COPYRIGHT_TERM : COMMONWEALTH_STANDARD_TERM;
}
Expand Down
97 changes: 76 additions & 21 deletions t/lib/CRMS/RightsPredictor.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,87 +24,143 @@ subtest 'RightsPredictor::last_source_copyright' => sub {
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000);
is($res->{last_source_copyright_year}, 2070);
is($res->{last_source_copyright_year}, 2070, 'UK baseline 70-year term');
};

subtest 'UK crown' => sub {
subtest 'UK corporate work' => sub {
my $f008 = '850423s1940 uk a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000, 1);
is($res->{last_source_copyright_year}, 2050);
is($res->{last_source_copyright_year}, 2070), 'UK corporate/anonymous 70-year term';
};

subtest 'UK crown' => sub {
my $f008 = '850423s1940 uk a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000, 0, 1);
is($res->{last_source_copyright_year}, 2050, 'UK crown copyright 50-year term');
};

subtest 'Canada pre-1972' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1970);
is($res->{last_source_copyright_year}, 2020);
is($res->{last_source_copyright_year}, 2020, 'Canada has 50-year term when the effective date is prior to 1972');
};

subtest 'Canada 1972' => sub {
subtest 'Canada 1972 author death date' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1972);
is($res->{last_source_copyright_year}, 2042);
is($res->{last_source_copyright_year}, 2042, 'Canada has 70-year term for author death dates on or after 1972');
};

subtest 'Canada 1972 corporate work' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1972, 1);
is($res->{last_source_copyright_year}, 2047, 'Canada has 75-year term for corporate/anonymous works published on or after 1972');
};

subtest 'Canada post-1972' => sub {
subtest 'Canada post-1972 author death date' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000);
is($res->{last_source_copyright_year}, 2070);
is($res->{last_source_copyright_year}, 2070, 'Canada has 70-year term for author death dates on or after 1972');
};

subtest 'Canada crown' => sub {
subtest 'Canada post-1972 corporate work' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000, 1);
is($res->{last_source_copyright_year}, 2050);
is($res->{last_source_copyright_year}, 2075, 'Canada has 75-year term for corporate/anonymous works published on or after 1972');
};

subtest 'Canada pre-1972 crown' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1970, 0, 1);
is($res->{last_source_copyright_year}, 2020, 'Canada has 50-year term for crown copyright works regardless of effective date');
};

subtest 'Canada 1972 crown' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1972, 0, 1);
is($res->{last_source_copyright_year}, 2022, 'Canada has 50-year term for crown copyright works regardless of effective date');
};

subtest 'Canada post-1972 crown' => sub {
my $f008 = '850423s1940 cn a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000, 0, 1);
is($res->{last_source_copyright_year}, 2050, 'Canada has 50-year term for crown copyright works regardless of effective date');
};

subtest 'Australia pre-1955' => sub {
my $f008 = '850423s1940 at a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1950);
is($res->{last_source_copyright_year}, 2000);
is($res->{last_source_copyright_year}, 2000, 'Australia has 50-year term when the effective date is prior to 1955');
};

subtest 'Australia 1955' => sub {
my $f008 = '850423s1940 at a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1955);
is($res->{last_source_copyright_year}, 2025);
is($res->{last_source_copyright_year}, 2025, 'Australia has 70-year term when the effective date is on or after 1955');
};

subtest 'Australia post-1955' => sub {
my $f008 = '850423s1940 at a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000);
is($res->{last_source_copyright_year}, 2070);
is($res->{last_source_copyright_year}, 2070, 'Australia has 70-year term when the effective date is on or after 1955');
};

subtest 'Australia crown' => sub {
subtest 'Australia pre-1955 crown' => sub {
my $f008 = '850423s1940 at a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000, 1);
is($res->{last_source_copyright_year}, 2050);
my $res = $rp->last_source_copyright(1940, 0, 1);
is($res->{last_source_copyright_year}, 1990, 'Australia has 50-year term for crown copyright works regardless of effective date');
};

subtest 'Australia 1955 crown' => sub {
my $f008 = '850423s1940 at a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(1955, 0, 1);
is($res->{last_source_copyright_year}, 2005, 'Australia has 50-year term for crown copyright works regardless of effective date');
};

subtest 'Australia post-1955 crown' => sub {
my $f008 = '850423s1940 at a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000, 0, 1);
is($res->{last_source_copyright_year}, 2050, 'Australia has 50-year term for crown copyright works regardless of effective date');
};

subtest 'Unknown country' => sub {
my $f008 = '850423s1940 a 000 0 eng d';
my $record = FakeMetadata::fake_record_with_008_and_leader($f008);
my $rp = CRMS::RightsPredictor->new(record => $record);
my $res = $rp->last_source_copyright(2000);
ok(!defined $res->{last_source_copyright_year});
ok(!defined $res->{last_source_copyright_year}, 'Last source copyright year cannot be defined for unknown country');
ok(join(', ', @{$res->{desc}}) =~ m/country/i);
};

Expand All @@ -115,7 +171,7 @@ subtest 'RightsPredictor::last_source_copyright' => sub {
my @bogus_years = (undef, 'abcd', '', 12345);
foreach my $year (@bogus_years) {
my $res = $rp->last_source_copyright($year);
ok(!defined $res->{last_source_copyright_year});
ok(!defined $res->{last_source_copyright_year}, 'Last source copyright year cannot be defined for unknown country');
ok(join(', ', @{$res->{desc}}) =~ m/unsupported/i);
}
};
Expand All @@ -127,8 +183,8 @@ subtest 'RightsPredictor::last_source_copyright' => sub {
my @ok_years = ('-1', '-0', '0000', 999999);
foreach my $year (@ok_years) {
my $res = $rp->last_source_copyright(2000);
ok(defined $res->{last_source_copyright_year});
ok(join(', ', $res->{desc}) !~ m/unsupported/i);
ok(defined $res->{last_source_copyright_year}, "Last source copyright year is defined even if the input is $year");
ok(join(', ', $res->{desc}) !~ m/unsupported/i, "No 'unsupported date format' error for $year");
}
};
};
Expand Down Expand Up @@ -243,4 +299,3 @@ subtest 'RightsPredictor::rights' => sub {
};

done_testing();

0 comments on commit fc68ca3

Please sign in to comment.