-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from koopjs/f/11798-dcat-3-feeds
update to dcat US 3.0
- Loading branch information
Showing
7 changed files
with
314 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Context header for DCAT US 1.1 | ||
export const HEADER_V_1X = { | ||
'@context': | ||
'https://project-open-data.cio.gov/v1.1/schema/catalog.jsonld', | ||
'@type': 'dcat:Catalog', | ||
conformsTo: 'https://project-open-data.cio.gov/v1.1/schema', | ||
describedBy: 'https://project-open-data.cio.gov/v1.1/schema/catalog.json', | ||
}; | ||
|
||
// Context header for DCAT US 3.0 | ||
// source: https://raw.githubusercontent.com/DOI-DO/dcat-us/refs/heads/main/context/dcat-us-3.0.jsonld | ||
export const HEADER_V_3_0 = { | ||
'@context': { | ||
'@version': 1.1, | ||
'@protected': true, | ||
'adms': 'http://www.w3.org/ns/adms#', | ||
'cnt': 'http://www.w3.org/2011/content#', | ||
'dash': 'http://datashapes.org/dash#', | ||
'dcat': 'http://www.w3.org/ns/dcat#', | ||
'dcatap': 'http://data.europa.eu/r5r/', | ||
'dcat-us': 'http://data.resources.gov/ontology/dcat-us#', | ||
'dcat-us-shp': 'http://data.resources.gov/shapes/dcat-us#', | ||
'dcterms': 'http://purl.org/dc/terms/', | ||
'dqv': 'http://www.w3.org/ns/dqv#', | ||
'foaf': 'http://xmlns.com/foaf/0.1/', | ||
'gsp': 'http://www.opengis.net/ont/geosparql#', | ||
'locn': 'http://www.w3.org/ns/locn#', | ||
'odrs': 'http://schema.theodi.org/odrs#', | ||
'org': 'http://www.w3c.org/ns/org#', | ||
'owl': 'http://www.w3.org/2002/07/owl#', | ||
'prov': 'http://www.w3.org/ns/prov#', | ||
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#', | ||
'schema': 'http://schema.org/', | ||
'sh': 'http://www.w3.org/ns/shacl#', | ||
'skos': 'http://www.w3.org/2004/02/skos/core#', | ||
'sdmx-attribute': 'http://purl.org/linked-data/sdmx/2009/attribute#', | ||
'spdx': 'http://spdx.org/rdf/terms#', | ||
'vcard': 'http://www.w3.org/2006/vcard/ns#', | ||
"xsd": "http://www.w3.org/2001/XMLSchema#", | ||
'adms:Identifier': { | ||
'@id': 'adms:Identifier', | ||
'@context': { | ||
'schemaAgency': 'http://www.w3.org/ns/adms#schemaAgency', | ||
'creator': { | ||
'@id': 'dcterms:creator', | ||
'@type': '@id' | ||
}, | ||
'issued': { | ||
'@id': 'dcterms:issued' | ||
}, | ||
'version': 'http://purl.org/dc/terms/version', | ||
'notation': 'http://www.w3.org/2004/02/skos/core#notation' | ||
} | ||
}, | ||
}, | ||
'@type': 'dcat:Catalog', | ||
conformsTo: 'https://resource.data.gov/profile/dcat-us#', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
import { compileDcatFeedEntry } from './compile-dcat-feed'; | ||
import { FeedFormatterStream } from './feed-formatter-stream'; | ||
import { TransformsList } from 'adlib'; | ||
import { HEADER_V_3_0, HEADER_V_1X } from './constants/contexts'; | ||
|
||
export function getDataStreamDcatUs11(feedTemplate: any, feedTemplateTransforms: TransformsList) { | ||
const catalogStr = JSON.stringify({ | ||
'@context': | ||
'https://project-open-data.cio.gov/v1.1/schema/catalog.jsonld', | ||
'@type': 'dcat:Catalog', | ||
conformsTo: 'https://project-open-data.cio.gov/v1.1/schema', | ||
describedBy: 'https://project-open-data.cio.gov/v1.1/schema/catalog.json', | ||
}, null, '\t'); | ||
export function getDataStreamDcatUs(feedTemplate: any, feedTemplateTransforms: TransformsList, version: string) { | ||
const footer = '\n\t]\n}'; | ||
let header: string; | ||
let template: Record<string, any>; | ||
|
||
const header = `${catalogStr.substr( | ||
0, | ||
catalogStr.length - 2, | ||
)},\n\t"dataset": [\n`; | ||
if (version === '3.0') { | ||
const { header: templateHeader, ...restFeedTemplate } = feedTemplate; | ||
template = restFeedTemplate; | ||
header = generateDcatUs3XHeader(templateHeader); | ||
} | ||
|
||
const footer = '\n\t]\n}'; | ||
if (version === '1.1') { | ||
template = feedTemplate; | ||
header = generateDcatUs1XHeader(); | ||
} | ||
|
||
const formatFn = (chunk) => { | ||
return compileDcatFeedEntry(chunk, feedTemplate, feedTemplateTransforms); | ||
return compileDcatFeedEntry(chunk, template, feedTemplateTransforms, version); | ||
}; | ||
|
||
return { | ||
stream: new FeedFormatterStream(header, footer, ',\n', formatFn) | ||
}; | ||
} | ||
} | ||
|
||
function generateDcatUs1XHeader() { | ||
const catalogStr = JSON.stringify(HEADER_V_1X, null, '\t'); | ||
return `${catalogStr.substring( | ||
0, | ||
catalogStr.length - 2, | ||
)},\n\t"dataset": [\n`; | ||
} | ||
|
||
function generateDcatUs3XHeader(header: Record<string, any>) { | ||
const catalogStr = JSON.stringify({ ...HEADER_V_3_0, ...header }, null, '\t'); | ||
return `${catalogStr.substring(0, catalogStr.length - 2)},\n\t"dcat:dataset": [\n`; | ||
} |
Oops, something went wrong.