From 16a327fc527e9678089f05855fe40c68bce4961b Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Tue, 17 Dec 2024 21:46:35 -0600 Subject: [PATCH 1/3] Add solution using KeyValueStrings. --- docs/recipes/0029-metadata-anywhere.md | 10 ++ .../scripts/0029-metadata-anywhere-method1.py | 98 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 docs/recipes/0029-metadata-anywhere.md create mode 100644 docs/recipes/scripts/0029-metadata-anywhere-method1.py diff --git a/docs/recipes/0029-metadata-anywhere.md b/docs/recipes/0029-metadata-anywhere.md new file mode 100644 index 0000000..bd65e32 --- /dev/null +++ b/docs/recipes/0029-metadata-anywhere.md @@ -0,0 +1,10 @@ +# Metadata on any Resource +| | **Cookbook URLs** | +|--------------|-------------------| +| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere/](https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere/) | +| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere/manifest.json](https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere/manifest.json) | + +### Method 1 - Use `KeyValueString` with AutoLang +```python +--8<-- "docs/recipes/scripts/0029-metadata-anywhere-method1.py" +``` diff --git a/docs/recipes/scripts/0029-metadata-anywhere-method1.py b/docs/recipes/scripts/0029-metadata-anywhere-method1.py new file mode 100644 index 0000000..8ea4b7e --- /dev/null +++ b/docs/recipes/scripts/0029-metadata-anywhere-method1.py @@ -0,0 +1,98 @@ +from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, HomepageItem, KeyValueString + +config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en" +base_url = "https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere" +manifest = Manifest( + id=f"{base_url}/manifest.json", + label = "John Dee performing an experiment before Queen Elizabeth I.", + metadata=[ + KeyValueString( + label="Creator", + value="Glindoni, Henry Gillard, 1852-1913" + ), + KeyValueString( + label="Date", + value="1800-1899" + ), + KeyValueString( + label="Physical Description", + value="1 painting : oil on canvas ; canvas 152 x 244.4 cm" + ), + KeyValueString( + label="Reference", + value="Wellcome Library no. 47369i" + ) + ], + requiredStatement=KeyValueString( + label="Attribution", + value="Wellcome Collection. Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)" + ) +) +hw = {"height": 1271, "width": 2000} +canvas = manifest.make_canvas( + id=f"{base_url}/canvas/p1", + label="Painting under natural light", + metadata=[ + KeyValueString( + label="Description", + value="The scene is the house at Mortlake of Dr John Dee (1527-1608). At the court of Queen Elizabeth I, Dee was revered for the range of his scientific knowledge, which embraced the fields of mathematics, navigation, geography, alchemy/chemistry, medicine and optics. In the painting he is showing the effect of combining two elements, either to cause combustion or to extinguish it. Behind him is his assistant Edward Kelly, wearing a long skullcap to conceal the fact that his ears had been cropped as a punishment for forgery." + ) + ] +) +canvas.set_hwd(**hw) +anno_body = ResourceItem( + id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg", + type="Image", + format="image/jpeg", +) +anno_body.set_hwd(**hw) +anno_body.make_service( + id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural", + profile="level1", + type="ImageService3", +) +anno_page = AnnotationPage( + id=f"{base_url}/page/p1/1" +) +anno = Annotation( + id=f"{base_url}/canvas/accompanying/annotation/image", + motivation="painting", + body=anno_body, + target=f"{base_url}/canvas/p1" +) +anno_page.add_item(anno) +canvas.add_item(anno_page) +canvas_2 = manifest.make_canvas( + id=f"{base_url}/canvas/p2", + label="X-ray view of painting", + metadata=[ + KeyValueString( + label="Description", + value="The painting originally showed Dee standing in a circle of skulls on the floor, stretching from the floor area in front of the Queen (on the left) to the floor near Edward Kelly (on the right). The skulls were at an early stage painted over, but have since become visible. Another pentimento is visible in the tapestry on the right: shelves containing monstrous animals are visible behind it. The pentimenti were clarified when the painting was X-rayed in 2015." + ) + ] +) +canvas_2.set_hwd(**hw) +anno_body_2 = ResourceItem( + id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-xray/full/max/0/default.jpg", + type="Image", + format="image/jpeg", +) +anno_body_2.set_hwd(**hw) +anno_body_2.make_service( + id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-xray", + profile="level1", + type="ImageService3", +) +anno_page_2 = AnnotationPage( + id=f"{base_url}/page/p2/1" +) +anno2 = Annotation( + id=f"{base_url}/annotation/p0002-image", + motivation="painting", + body=anno_body_2, + target=f"{base_url}/canvas/p2" +) +anno_page_2.add_item(anno2) +canvas_2.add_item(anno_page_2) +print(manifest.json(indent=2)) \ No newline at end of file From f7865bca1846eea1d53c704a317ee9f45bff6b6f Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Tue, 17 Dec 2024 21:53:00 -0600 Subject: [PATCH 2/3] Fix id. --- docs/recipes/scripts/0029-metadata-anywhere-method1.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/recipes/scripts/0029-metadata-anywhere-method1.py b/docs/recipes/scripts/0029-metadata-anywhere-method1.py index 8ea4b7e..39aaa64 100644 --- a/docs/recipes/scripts/0029-metadata-anywhere-method1.py +++ b/docs/recipes/scripts/0029-metadata-anywhere-method1.py @@ -1,7 +1,8 @@ -from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, HomepageItem, KeyValueString +from iiif_prezi3 import Manifest, ResourceItem, AnnotationPage, Annotation, config, KeyValueString config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en" base_url = "https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere" + manifest = Manifest( id=f"{base_url}/manifest.json", label = "John Dee performing an experiment before Queen Elizabeth I.", @@ -55,7 +56,7 @@ id=f"{base_url}/page/p1/1" ) anno = Annotation( - id=f"{base_url}/canvas/accompanying/annotation/image", + id=f"{base_url}/canvas/annotation/p0001-image", motivation="painting", body=anno_body, target=f"{base_url}/canvas/p1" @@ -95,4 +96,5 @@ ) anno_page_2.add_item(anno2) canvas_2.add_item(anno_page_2) -print(manifest.json(indent=2)) \ No newline at end of file + +print(manifest.json(indent=2)) From 0e5085d189249a981315f9f1fa9d0c247e8579a4 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Tue, 17 Dec 2024 21:58:20 -0600 Subject: [PATCH 3/3] Fix id. --- docs/recipes/scripts/0029-metadata-anywhere-method1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/recipes/scripts/0029-metadata-anywhere-method1.py b/docs/recipes/scripts/0029-metadata-anywhere-method1.py index 39aaa64..7908cc3 100644 --- a/docs/recipes/scripts/0029-metadata-anywhere-method1.py +++ b/docs/recipes/scripts/0029-metadata-anywhere-method1.py @@ -56,7 +56,7 @@ id=f"{base_url}/page/p1/1" ) anno = Annotation( - id=f"{base_url}/canvas/annotation/p0001-image", + id=f"{base_url}/annotation/p0001-image", motivation="painting", body=anno_body, target=f"{base_url}/canvas/p1"