From 1d84db0d58198326cb320f7400916f09f9914e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Fri, 3 Nov 2023 11:45:22 +0100 Subject: [PATCH] Add metadata to manifest - WIP --- controllers/manifest.mjs | 11 +++++++- src/Image.js | 4 ++- src/Manifest.js | 13 +++++++-- src/Metadata.js | 61 ++++++++++++++++++++++++++++++++++++++++ src/common.js | 27 +++++++++++++++--- 5 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/Metadata.js diff --git a/controllers/manifest.mjs b/controllers/manifest.mjs index 160e073..7e5e22d 100644 --- a/controllers/manifest.mjs +++ b/controllers/manifest.mjs @@ -14,12 +14,21 @@ export default async function generateManifest(manifestId) { let manifest = new Manifest(IIIF_API_VERSION, BASE_URL); manifest.generateID(manifestId); manifest.generateLabel(); + + const images = await Common.getImageList(manifestId); manifest = await Common.populateCanvases( manifest, - await Common.getImageList(manifestId), + images, manifestId ); + manifest.setMetadata( + Common.createMetadata( + manifest, + images[0], + ) + ); + return manifest.toObject(); } diff --git a/src/Image.js b/src/Image.js index 821b5d4..2447a33 100644 --- a/src/Image.js +++ b/src/Image.js @@ -1,5 +1,8 @@ import IIIFResource from './IIIFResource.js'; +/** + * @todo Move to common.js?! + */ const splitter = { NIR: splitNIR, DN: splitDNO, @@ -60,7 +63,6 @@ class Image { /** * Generate IIIF id pointing to image * server endpoint for this image - * @todo Warning! Only works for NIR filenames... * @param {string} serviceURL The image server base URL * @param {string} filename The image's complete filename */ diff --git a/src/Manifest.js b/src/Manifest.js index b3ebed9..a0ad040 100644 --- a/src/Manifest.js +++ b/src/Manifest.js @@ -1,9 +1,7 @@ import IIIFResource from './IIIFResource.js'; import Sequence from "./Sequence.js"; +import ManifestMetadata from './Metadata.js'; -const TECH = { - nir: "Technical Photography, Near Infrared Imaging 1000nm", -} /** * @implements IIIFResource */ @@ -12,6 +10,7 @@ class Manifest { #type = 'sc:Manifest'; #label = ''; resourceId = ''; + #metadata = {}; #technique = ''; /** * @var {Sequence[]} @@ -46,6 +45,13 @@ class Manifest { generateLabel() { this.#label = `P.Herc. ${this.resourceId.split('-')[1]}`; } + /** + * + * @param {ManifestMetadata} metadata + */ + setMetadata(metadata) { + this.#metadata = metadata.toObject(); + } /** * Object representation of this * manifest @@ -57,6 +63,7 @@ class Manifest { "@id" : this.id, "@type" : this.#type, label : this.#label, + metadata: this.#metadata, sequences: this.sequences, } } diff --git a/src/Metadata.js b/src/Metadata.js new file mode 100644 index 0000000..8ae72cd --- /dev/null +++ b/src/Metadata.js @@ -0,0 +1,61 @@ + +class ManifestMetadata { + papyrus = ''; + author = ''; + title = ''; + edition = ''; + technique = ''; + date = ''; + imageAuthor = ''; + license = 'CC BY-NC-ND 4.0'; + copyright = 'BNN/CNR-ISPC'; + + /** + * @todo Maybe this doesn't make any sense?? + * @param { + * {papyrus, + * author, + * title, + * edition, + * technique, + * date, + * imageAuthor, + * license, + * copyright} + * } metadata + */ + constructor(metadata) { + this.papyrus = metadata.papyrus ?? this.papyrus; + this.author = metadata.author ?? this.author; + this.title = metadata.title ?? this.title; + this.edition = metadata.edition ?? this.edition; + // There should always be a technique value + // in the metadata param + this.technique = metadata.technique; + this.date = metadata.date ?? this.date; + this.imageAuthor = metadata.imageAuthor ?? this.imageAuthor + this.license = metadata.license ?? this.license; + this.copyright = metadata.copyright ?? this.copyright; + } + + /** + * Returns an array of `label, value` + * pairs for all metadata + * @returns {Array<{label, value}>} + */ + toObject() { + return [ + {label: "Papyrus", value: this.papyrus}, + {label:"Author", value: this.author}, + {label:"Title", value: this.title}, + {label:"Reference edition", value: this.edition}, + {label:"Technique", value: this.technique}, + {label:"Date (Year)", value: this.date}, + {label:"Image Author", value: this.imageAuthor}, + {label:"License", value: this.license}, + {label:"Copyright", value: this.copyright}, + ] + } +} + +export default ManifestMetadata; \ No newline at end of file diff --git a/src/common.js b/src/common.js index bebe2e0..fdc3ab6 100644 --- a/src/common.js +++ b/src/common.js @@ -6,7 +6,7 @@ import Manifest from './Manifest.js'; import Sequence from './Sequence.js'; import Canvas from './Canvas.js'; import Image from './Image.js'; -//import ManifestMetadata from './Metadata.js'; +import ManifestMetadata from './Metadata.js'; const Common = {}; const TECH_NAMES = { @@ -80,11 +80,13 @@ Common.createCanvas = async function (manifest, filename) { process.env.IIIF_API_VERSION, process.env.BASE_URL ); + const namePos = { nir: 1, do: 3, dn: 3 }; + const canvasName = filename.split('_')[namePos[manifest.technique]] .replace(/\.\w{1,3}$/, ''); canvas.generateID(manifest.resourceId, canvasName); @@ -140,13 +142,30 @@ Common.populateCanvases = async function (manifest, images) { } /** * @todo Implement... - * @param {string} imageName The image filename + * @param {Manifest} manifest The Manifest object + * @param {string} imgFilename * @returns {ManifestMetadata} */ -Common.createMetadata = function (imageName) { - let metadata = {}; +Common.createMetadata = function (manifest, imgFilename) { + let metadata = this.getMetadataFromImgName(imgFilename); + metadata.technique = TECH_NAMES[manifest.technique]; return new ManifestMetadata(metadata); } +/** + * @todo Only works with NIR!! + * @param {string} imgFilename + */ +Common.getMetadataFromImgName = function (imgFilename) { + const authors = { + DAN: 'Danilo P. Pavone' + }; + + return { + papyrus: imgFilename.split('_')[0].split('-')[2], + imageAuthor: authors[imgFilename.split('-')[0].replace(/\d{4}/,'')], + date: imgFilename.split('-')[0].match(/\d{4}/)[0], + } +} export default Common; \ No newline at end of file