Add metadata to manifest - WIP

This commit is contained in:
Nicolò P 2023-11-03 11:45:22 +01:00
parent d707457cb8
commit 1d84db0d58
5 changed files with 107 additions and 9 deletions

View File

@ -14,12 +14,21 @@ export default async function generateManifest(manifestId) {
let manifest = new Manifest(IIIF_API_VERSION, BASE_URL); let manifest = new Manifest(IIIF_API_VERSION, BASE_URL);
manifest.generateID(manifestId); manifest.generateID(manifestId);
manifest.generateLabel(); manifest.generateLabel();
const images = await Common.getImageList(manifestId);
manifest = await Common.populateCanvases( manifest = await Common.populateCanvases(
manifest, manifest,
await Common.getImageList(manifestId), images,
manifestId manifestId
); );
manifest.setMetadata(
Common.createMetadata(
manifest,
images[0],
)
);
return manifest.toObject(); return manifest.toObject();
} }

View File

@ -1,5 +1,8 @@
import IIIFResource from './IIIFResource.js'; import IIIFResource from './IIIFResource.js';
/**
* @todo Move to common.js?!
*/
const splitter = { const splitter = {
NIR: splitNIR, NIR: splitNIR,
DN: splitDNO, DN: splitDNO,
@ -60,7 +63,6 @@ class Image {
/** /**
* Generate IIIF id pointing to image * Generate IIIF id pointing to image
* server endpoint for this image * server endpoint for this image
* @todo Warning! Only works for NIR filenames...
* @param {string} serviceURL The image server base URL * @param {string} serviceURL The image server base URL
* @param {string} filename The image's complete filename * @param {string} filename The image's complete filename
*/ */

View File

@ -1,9 +1,7 @@
import IIIFResource from './IIIFResource.js'; import IIIFResource from './IIIFResource.js';
import Sequence from "./Sequence.js"; import Sequence from "./Sequence.js";
import ManifestMetadata from './Metadata.js';
const TECH = {
nir: "Technical Photography, Near Infrared Imaging 1000nm",
}
/** /**
* @implements IIIFResource * @implements IIIFResource
*/ */
@ -12,6 +10,7 @@ class Manifest {
#type = 'sc:Manifest'; #type = 'sc:Manifest';
#label = ''; #label = '';
resourceId = ''; resourceId = '';
#metadata = {};
#technique = ''; #technique = '';
/** /**
* @var {Sequence[]} * @var {Sequence[]}
@ -46,6 +45,13 @@ class Manifest {
generateLabel() { generateLabel() {
this.#label = `P.Herc. ${this.resourceId.split('-')[1]}`; this.#label = `P.Herc. ${this.resourceId.split('-')[1]}`;
} }
/**
*
* @param {ManifestMetadata} metadata
*/
setMetadata(metadata) {
this.#metadata = metadata.toObject();
}
/** /**
* Object representation of this * Object representation of this
* manifest * manifest
@ -57,6 +63,7 @@ class Manifest {
"@id" : this.id, "@id" : this.id,
"@type" : this.#type, "@type" : this.#type,
label : this.#label, label : this.#label,
metadata: this.#metadata,
sequences: this.sequences, sequences: this.sequences,
} }
} }

61
src/Metadata.js Normal file
View File

@ -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;

View File

@ -6,7 +6,7 @@ import Manifest from './Manifest.js';
import Sequence from './Sequence.js'; import Sequence from './Sequence.js';
import Canvas from './Canvas.js'; import Canvas from './Canvas.js';
import Image from './Image.js'; import Image from './Image.js';
//import ManifestMetadata from './Metadata.js'; import ManifestMetadata from './Metadata.js';
const Common = {}; const Common = {};
const TECH_NAMES = { const TECH_NAMES = {
@ -80,11 +80,13 @@ Common.createCanvas = async function (manifest, filename) {
process.env.IIIF_API_VERSION, process.env.IIIF_API_VERSION,
process.env.BASE_URL process.env.BASE_URL
); );
const namePos = { const namePos = {
nir: 1, nir: 1,
do: 3, do: 3,
dn: 3 dn: 3
}; };
const canvasName = filename.split('_')[namePos[manifest.technique]] const canvasName = filename.split('_')[namePos[manifest.technique]]
.replace(/\.\w{1,3}$/, ''); .replace(/\.\w{1,3}$/, '');
canvas.generateID(manifest.resourceId, canvasName); canvas.generateID(manifest.resourceId, canvasName);
@ -140,13 +142,30 @@ Common.populateCanvases = async function (manifest, images) {
} }
/** /**
* @todo Implement... * @todo Implement...
* @param {string} imageName The image filename * @param {Manifest} manifest The Manifest object
* @param {string} imgFilename
* @returns {ManifestMetadata} * @returns {ManifestMetadata}
*/ */
Common.createMetadata = function (imageName) { Common.createMetadata = function (manifest, imgFilename) {
let metadata = {}; let metadata = this.getMetadataFromImgName(imgFilename);
metadata.technique = TECH_NAMES[manifest.technique];
return new ManifestMetadata(metadata); 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; export default Common;