Skip to content

Commit

Permalink
Added code to generate a compiled JSON of all raw data from ASCT+B ta…
Browse files Browse the repository at this point in the history
…bles for a collection (needed for CxG collab)
  • Loading branch information
bherr2 committed Jun 10, 2024
1 parent 14eadf3 commit cc29ecd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"printWidth": 120
}
10 changes: 10 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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('<collection-path>', 'Path to the collection digital object relative to DO_HOME')
.option('-o, --output <json-path>', 'Path to the output JSON file to generate')
.action((str, _options, command) => {
genAsctbCollectionJson(getContext(program, command, str));
});

program
.command('enrich')
.description(
Expand Down
24 changes: 24 additions & 0 deletions src/gen-asctb-collection-json.js
Original file line number Diff line number Diff line change
@@ -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));
}
6 changes: 3 additions & 3 deletions src/normalization/normalize-asct-b.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,7 +53,7 @@ async function getRawData(context) {
more(`Please review the warnings at ${warningsFile}`);
}

return data.data;
return data;
}

function normalizeData(context, data) {
Expand Down

0 comments on commit cc29ecd

Please sign in to comment.