Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Metadata Anywhere recipe. #217

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/recipes/0029-metadata-anywhere.md
Original file line number Diff line number Diff line change
@@ -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"
```
100 changes: 100 additions & 0 deletions docs/recipes/scripts/0029-metadata-anywhere-method1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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.",
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}/annotation/p0001-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))
Loading