From cc29ecd5accd87f40f09e190a0cc5196666e55b4 Mon Sep 17 00:00:00 2001 From: "Bruce W. Herr II" Date: Mon, 10 Jun 2024 09:47:35 -0400 Subject: [PATCH] Added code to generate a compiled JSON of all raw data from ASCT+B tables for a collection (needed for CxG collab) --- .prettierrc | 3 ++- src/cli.js | 10 ++++++++++ src/gen-asctb-collection-json.js | 24 ++++++++++++++++++++++++ src/normalization/normalize-asct-b.js | 6 +++--- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/gen-asctb-collection-json.js diff --git a/.prettierrc b/.prettierrc index 544138b..0981b7c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,4 @@ { - "singleQuote": true + "singleQuote": true, + "printWidth": 120 } diff --git a/src/cli.js b/src/cli.js index 0ad1ebf..520722b 100755 --- a/src/cli.js +++ b/src/cli.js @@ -7,6 +7,7 @@ import { bumpDraft } from './drafting/bump-draft.js'; import { newDraft } from './drafting/new-draft.js'; import { enrich } from './enrichment/enrich.js'; import { finalize } from './finalizing/finalize.js'; +import { genAsctbCollectionJson } from './gen-asctb-collection-json.js'; import { list } from './list.js'; import { migrateCcfLandmarks } from './migration/ccf-landmarks/migrate.js'; import { migrateCcfOwl } from './migration/ccf-owl/migrate.js'; @@ -82,6 +83,15 @@ program updateRefOrganCrosswalk(getContext(program, command, str)); }); +program + .command('gen-asct-b-collection-json') + .description('Generate a json file of all raw ASCT+B data in json format from a given collection.') + .argument('', 'Path to the collection digital object relative to DO_HOME') + .option('-o, --output ', 'Path to the output JSON file to generate') + .action((str, _options, command) => { + genAsctbCollectionJson(getContext(program, command, str)); + }); + program .command('enrich') .description( diff --git a/src/gen-asctb-collection-json.js b/src/gen-asctb-collection-json.js new file mode 100644 index 0000000..98944a6 --- /dev/null +++ b/src/gen-asctb-collection-json.js @@ -0,0 +1,24 @@ +import { readFileSync, writeFileSync } from 'fs'; +import { load } from 'js-yaml'; +import { resolve } from 'path'; +import { getRawData } from './normalization/normalize-asct-b.js'; +import { getDigitalObjectInformation } from './utils/digital-object.js'; + +export async function genAsctbCollectionJson(context) { + const obj = context.selectedDigitalObject; + const doListing = resolve(obj.path, 'raw/digital-objects.yaml'); + const childObjects = load(readFileSync(doListing))['digital-objects']; + const asctbObjects = childObjects.filter((obj) => obj.startsWith('asct-b/') && !obj.includes('-crosswalk/')); + + const result = {}; + for (const doName of asctbObjects) { + const obj = getDigitalObjectInformation(resolve(context.doHome, doName), context.purlIri); + const rawData = await getRawData({ + ...context, + selectedDigitalObject: obj, + }); + result[obj.name] = rawData; + } + + writeFileSync(context.output, JSON.stringify(result, null, 2)); +} diff --git a/src/normalization/normalize-asct-b.js b/src/normalization/normalize-asct-b.js index bd3cf00..233433d 100644 --- a/src/normalization/normalize-asct-b.js +++ b/src/normalization/normalize-asct-b.js @@ -25,11 +25,11 @@ export function normalizeAsctbMetadata(context) { export async function normalizeAsctbData(context) { const rawData = await getRawData(context); - const normalizedData = normalizeData(context, rawData); + const normalizedData = normalizeData(context, rawData).data; writeNormalizedData(context, normalizedData); } -async function getRawData(context) { +export async function getRawData(context) { const { path } = context.selectedDigitalObject; const metadata = readMetadata(context); @@ -53,7 +53,7 @@ async function getRawData(context) { more(`Please review the warnings at ${warningsFile}`); } - return data.data; + return data; } function normalizeData(context, data) {