Print

Print


might be worth spending a minute on some AI bots to play with this

at the end of the day it's an XML->JSON project and there are a bunch of tools that will streamline that

for instance here's a dumbed down python script with a streamlit interface i got out of claude.ai in a couple of queries


import streamlit as st
import xml.etree.ElementTree as ET
import json

st.title('METS to JSON-LD Converter')

uploaded_file = st.file_uploader('Choose a METS XML file', type=['xml'])

if uploaded_file is not None:
    # Load METS file
    tree = ET.parse(uploaded_file)
    root = tree.getroot()

    # JSON-LD context
    context = {
        '@vocab': 'http://schema.org/',
        'dc': 'http://purl.org/dc/elements/1.1/'
    }

    jsonld = {'@context': context}
    jsonld['metadata'] = []

    # Parse METS and generate JSON-LD
    for dmdSec in root.iter('dmdSec'):
        # Extract metadata
        md = {
            'name': dmdSec.find('mdWrap/xmlData/mods/titleInfo/title').text,
            'author': [{'@type': 'Person', 'name': namePart.text} for namePart in dmdSec.find('mdWrap/xmlData/mods/name')],
            'datePublished': dmdSec.find('mdWrap/xmlData/mods/originInfo/dateIssued').text,
            'publisher': {'@type': 'Organization', 'name': dmdSec.find('mdWrap/xmlData/mods/originInfo/publisher').text},
            'genre': dmdSec.find('mdWrap/xmlData/mods/genre').text,
            'description': dmdSec.find('mdWrap/xmlData/mods/abstract').text
        }

        jsonld['metadata'].append(md)

    # Output JSON-LD file for download
    json_txt = json.dumps(jsonld, indent=4)
    st.download_button('Download JSON-LD', json_txt, 'metadata.jsonld')

________________________________________
From: Code for Libraries <[log in to unmask]> on behalf of Manuela Pallotto Strickland <[log in to unmask]>
Sent: Tuesday, August 1, 2023 10:47 AM
To: [log in to unmask]
Subject: [CODE4LIB] METS in JSON-LD?

Hello,
I am posting this question on a couple of lists, so sincere apologies to those who might see it twice (or thrice).
Does anyone know of any work that has been/is being/will be done on 'a' METS JSON-LD serialization?
Any relevant info or comment in this re will be very much appreciated.
Thank you!
Best wishes,
Manuela


__________________________________________________________________________________

Dr Manuela Pallotto Strickland | Metadata and Digital Preservation Coordinator | Archives & Research Collections | Libraries & Collections
King's College London | Strand | London WC2R 2LS | [log in to unmask]<mailto:[log in to unmask]>
Tel: Please call me using MS Teams or Skype for Business, or email to arrange a call

W: https://www.kcl.ac.uk/library/collections/archives
T: twitter.com/KingsArchives<http://twitter.com/KingsArchives> and twitter.com/kingslibraries<http://twitter.com/kingslibraries>
Blog: blogs.kcl.ac.uk/kingscollections<http://blogs.kcl.ac.uk/kingscollections>