Skip to content

Commit

Permalink
Fix f540 and f856 generators (#186)
Browse files Browse the repository at this point in the history
* Fix f540 generation: uses now only predefined mappings for generating copyright note
* Fix f856 generation logic
  • Loading branch information
aatuny authored Nov 12, 2024
1 parent ee035c5 commit 651c236
Show file tree
Hide file tree
Showing 46 changed files with 433 additions and 105 deletions.
84 changes: 50 additions & 34 deletions src/transform/convert/common/generate5xx.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,49 +178,65 @@ export function generate506({getFieldValues}) {
* @returns Empty array or array containing field 540
*/
export function generate540({getFieldValues}) {
if (blockGeneration({getFieldValues})) {
const rightsValues = getFieldValues('dc.rights');

if (blockGeneration(rightsValues)) {
return [];
}

const rights = generateRights();
const uri = generateUri();
const url = generateUrl();

return rights.concat(uri, url);

function generateRights() {
const values = getFieldValues('dc.rights');
return values.map(value => {
const subfields = generateSubfields();
return {tag: '540', ind1: '', ind2: '', subfields};

function generateSubfields() {
return (/All rights reserved/u).test(value) ? [{code: 'a', value}] : [{code: 'c', value}];
}
});
}
const fieldMap = {
'cc by-nc-nd 4.0': {
value: 'CC BY-NC-ND 4.0',
url: 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi'
},
'cc by-sa 4.0': {
value: 'CC BY-SA 4.0',
url: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fi'
},
'cc by-sa 4.0 nimeä-jaasamoin': {
value: 'CC BY-SA 4.0',
url: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fi'
},
'cc by-nd 4.0': {
value: 'CC BY-ND 4.0',
url: 'https://creativecommons.org/licenses/by-nd/4.0/deed.fi'
},
'cc by-nc 4.0': {
value: 'CC BY-NC 4.0',
url: 'https://creativecommons.org/licenses/by-nc/4.0/deed.fi'
},
'cc by-nc-sa 4.0': {
value: 'CC BY-NC-SA 4.0',
url: 'https://creativecommons.org/licenses/by-nc-sa/4.0/deed.fi'
},
'cc by 4.0': {
value: 'CC BY 4.0',
url: 'https://creativecommons.org/licenses/by/4.0/deed.fi'
}
};

function generateUri() {
const values = getFieldValues('dc.rights.uri');
return values.map(value => ({
return rightsValues
.map(v => v.toLowerCase())
.filter(v => Object.keys(fieldMap).includes(v))
.map(k => ({
tag: '540', ind1: '', ind2: '',
subfields: [{code: 'u', value}]
subfields: [
{code: 'f', value: fieldMap[k].value},
{code: '2', value: 'cc'},
{code: 'u', value: fieldMap[k].url}
]
}));
}

function generateUrl() {
const values = getFieldValues('dc.rights.url');
return values.map(value => ({
tag: '540', ind1: '', ind2: '',
subfields: [{code: 'u', value}]
}));
}

function blockGeneration({getFieldValues}) {
const rightsFields = getFieldValues('dc.rights');
const blockValues = ['This publication is copyrighted. You may download, display and print it for Your own personal use. Commercial use is prohibited.'];
function blockGeneration(rightsValues) {
const blockValues = [
'This publication is copyrighted. You may download, display and print it for Your own personal use. Commercial use is prohibited.',
'Tekijänoikeuslaki (404/1961) 9 § Tekijänoikeussuojaa vailla olevat teokset',
'Upphovsrättslag (404/1961) 9 § Verk utan upphovsrättsskydd',
'Copyright Act (404/1961) 9 § Works excluded from protection'
];

return rightsFields.some(v => blockValues.includes(v));
return rightsValues.some(v => blockValues.includes(v));
}
}

Expand Down
84 changes: 49 additions & 35 deletions src/transform/convert/common/generate8xx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,82 @@ import {isOpenAccess, isValidLink} from '../util';
import {sourceConfig} from '../../../config';

/**
* Generates field 856 ($u: optional, $y: optional).
* Field generation is based on dc.rights.accesslevel value.
* 856 fields relating to publicly available access prioritization:
* URN and DOI > URI and URL.
* Generates field 856 ($u, $y: optional).
* @param {Object} ValueInterface containing getFieldValues function
* @returns Empty array or array containing field 856 ($u, $y)
*/
export function generate856({getFieldValues}) {
const publicAccessFields = generatePublicAccessFields();
const otherUrnFields = generateOtherUrnFields();
const publicAccessFields = generatePublicAccessFields({getFieldValues});
const otherUrnFields = generateOtherUrnFields({getFieldValues});

return publicAccessFields.concat(otherUrnFields);

function generatePublicAccessFields() {
/**
* Generation prioritization if open access fields are to be generated:
* 1. If dc.identifier.urn has value(s), generate subfields using all these values
* 2. If dc.identifier.doi/dc.identifier.uri have value(s), generate subfields using all these values
*/
function generatePublicAccessFields({getFieldValues}) {
const openAccess = isOpenAccess({getFieldValues});

// NB: not having access level fields generates f856 public access field
if (openAccess) {
const subfields = generateSubfields();
const subfields = generateSubfields({getFieldValues});
return subfields.length > 0 ? [{tag: '856', ind1: '4', ind2: '0', subfields}] : [];
}

return [];

function generateSubfields() {
const linkSubfields = generateLinkSubfields();

function generateSubfields({getFieldValues}) {
const linkSubfields = generateLinkSubfields({getFieldValues});
return linkSubfields.length > 0 ? linkSubfields.concat({code: 'y', value: 'Linkki verkkoaineistoon'}) : [];
}
}

function generateOtherUrnFields() {
const urn = getFieldValues('dc.relation.urn');
function generateLinkSubfields({getFieldValues}) {
const urn = generateUrn({getFieldValues});
const doi = generateU('dc.identifier.doi', {getFieldValues});
const uri = generateU('dc.identifier.uri', {getFieldValues});

return urn.length > 0 ? [
{
tag: '856', ind1: '4', ind2: '2',
subfields: [{code: 'u', value: urn[0]}]
if (urn.length > 0) {
return urn;
}
] : [];
}

function generateLinkSubfields() {
const urn = generateUrn();
const doi = generateU('dc.identifier.doi');
const uri = generateU('dc.identifier.uri');
const url = generateU('dc.identifier.url');
return doi.concat(uri);

if (urn.length > 0) {
return doi ? urn.concat(doi) : urn;
// NB: URN needs to be in proper format (http|https://urn.fi/<value>) or otherwise it will not be used in subfield generation
function generateUrn({getFieldValues}) {
const values = getFieldValues('dc.identifier.urn');
return values
.filter(urnIsValid)
.map(mapUrnValue)
.map(v => ({code: 'u', value: v}));
}

function generateU(path, {getFieldValues}) {
const values = getFieldValues(path);
return values.filter(value => isValidLink(value)).map(value => ({code: 'u', value}));
}
}
}

return doi.concat(uri, url);
function generateOtherUrnFields({getFieldValues}) {
const urn = getFieldValues('dc.relation.urn');
const firstUrnValue = urn.length > 0 ? urn[0] : null;
const validUrn = urnIsValid(firstUrnValue);

function generateUrn() {
const values = getFieldValues('dc.identifier.urn');
return values.map(v => ({code: 'u', value: (/http:\/\/urn.fi\//u).test(v) ? v : `http://urn.fi/${v}`}));
if (!firstUrnValue || !validUrn) {
return [];
}

function generateU(path) {
const values = getFieldValues(path);
return values.filter(value => isValidLink(value)).map(value => ({code: 'u', value}));
}
return [{tag: '856', ind1: '4', ind2: '2', subfields: [{code: 'u', value: mapUrnValue(firstUrnValue)}]}];
}

function urnIsValid(urn) {
return (/https?:\/\/urn.fi\//u).test(urn) || (/^URN:/u).test(urn);
}

function mapUrnValue(urn) {
return (/https?:\/\/urn.fi\//u).test(urn) ? urn : `http://urn.fi/${urn}`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,5 @@
"element": "rights",
"value": "CC BY 4.0"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "url",
"value": "https://creativecommons.org/licenses/by/4.0/"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "uri",
"value": "https://creativecommons.org/licenses/by/4.0/deed.en"
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"description": "Generates f540 from each dc.rights, dc.rights.url and dc.rights.uri information",
"description": "Generates f540 for CC BY 4.0 using predefined mapping",
"only": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@
{
"tag": "540", "ind1": "", "ind2": "",
"subfields": [
{"code": "c", "value": "CC BY 4.0"}
]
},
{
"tag": "540", "ind1": "", "ind2": "",
"subfields": [
{"code": "u", "value": "https://creativecommons.org/licenses/by/4.0/deed.en"}
]
},
{
"tag": "540", "ind1": "", "ind2": "",
"subfields": [
{"code": "u", "value": "https://creativecommons.org/licenses/by/4.0/"}
{"code": "f", "value": "CC BY 4.0"},
{"code": "2", "value": "cc"},
{"code": "u", "value": "https://creativecommons.org/licenses/by/4.0/deed.fi"}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"$": {
"schema": "dc",
"element": "rights",
"value": "CC BY 4.0"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "url",
"value": "https://creativecommons.org/licenses/by/4.0/"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "uri",
"value": "https://creativecommons.org/licenses/by/4.0/deed.en"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"value": "Tekijänoikeuslaki (404/1961) 9 § Tekijänoikeussuojaa vailla olevat teokset"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Blocks generation of f540 if dc.rights has note regarding exclusion from protection (Finnish)",
"only": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"$": {
"schema": "dc",
"element": "rights",
"value": "CC BY 4.0"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "url",
"value": "https://creativecommons.org/licenses/by/4.0/"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "uri",
"value": "https://creativecommons.org/licenses/by/4.0/deed.en"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"value": "Upphovsrättslag (404/1961) 9 § Verk utan upphovsrättsskydd"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Blocks generation of f540 if dc.rights has note regarding exclusion from protection (Swedish)",
"only": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"$": {
"schema": "dc",
"element": "rights",
"value": "CC BY 4.0"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "url",
"value": "https://creativecommons.org/licenses/by/4.0/"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"qualifier": "uri",
"value": "https://creativecommons.org/licenses/by/4.0/deed.en"
}
},
{
"$": {
"schema": "dc",
"element": "rights",
"value": "Copyright Act (404/1961) 9 § Works excluded from protection"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Blocks generation of f540 if dc.rights has note regarding exclusion from protection (English)",
"only": false
}
Loading

0 comments on commit 651c236

Please sign in to comment.