Skip to content
Snippets Groups Projects
Commit 84c59bdd authored by Mike Lynch's avatar Mike Lynch
Browse files

Spatials are passing, though the geospatial stuff needs work

parent 906cc955
Branches
Tags
No related merge requests found
...@@ -436,13 +436,30 @@ function make_spatial(datapub, prefix) { ...@@ -436,13 +436,30 @@ function make_spatial(datapub, prefix) {
return { return {
'@id': id, '@id': id,
'identifier': id, 'identifier': id,
'description': gl '@type': 'Place',
'name': gl['basic_name'],
'geo': {
'@type': "GeoCoordinates",
'latitude': gl['latitude'],
'longitude': gl['longitude']
}
} }
}); });
} }
if( datapub['geospatial'] ) { if( datapub['geospatial'] ) {
// FIXME - need to see what this looks like in a real record // these are GeoJSON, for which there is a JSON-LD context
// defined here: http://geojson.org/geojson-ld/
// TODO: append it to the context.
// for now I'm just passing it through to an item with the
// @type from the GeoJSON type
const id = prefix + String(i);
items.push({
'@id': id,
'identifier': id,
'@type': datapub['geospatial']['type'],
'name': id,
'features': datapub['geospatial']['features']
})
} }
return items; return items;
} }
......
...@@ -33,6 +33,21 @@ const ORG = { ...@@ -33,6 +33,21 @@ const ORG = {
'name': 'University of Technology Sydney' 'name': 'University of Technology Sydney'
}; };
// defining these here so that the tests know what to
// look up in the results @graph
const IRI_PREFIXES = {
'about': {
'dc:subject_anzsrc:for': '_:FOR/',
'dc:subject_anzsrc:seo': '_:SEO/'
},
'spatialCoverage': '_:spatial/',
'funder': '_:funder/',
'licence': '_:licence/',
'citation': '_:citation/'
};
const OWNER = 'https://orcid.org/0000-0001-5152-5307'; const OWNER = 'https://orcid.org/0000-0001-5152-5307';
const APPROVER = 'admin'; const APPROVER = 'admin';
...@@ -55,6 +70,14 @@ function get_id(c, id) { ...@@ -55,6 +70,14 @@ function get_id(c, id) {
} }
} }
// this is for fetching all of the items with the prefix for
// spatialCoverage items, say.
function get_id_prefix(c, prefix) {
return c['@graph'].filter((item) => item['@id'].startsWith(prefix));
}
// this one returns an array of items with the requested type // this one returns an array of items with the requested type
function get_type(c, t) { function get_type(c, t) {
...@@ -62,6 +85,8 @@ function get_type(c, t) { ...@@ -62,6 +85,8 @@ function get_type(c, t) {
} }
var mdp, dp, cj, cjds; var mdp, dp, cj, cjds;
...@@ -79,7 +104,8 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { ...@@ -79,7 +104,8 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
'datapub': dp, 'datapub': dp,
'organisation': ORG, 'organisation': ORG,
'owner': OWNER, 'owner': OWNER,
'approver': APPROVER 'approver': APPROVER,
'prefixes': IRI_PREFIXES
}); });
const roots = cj['@graph'].filter((item) => {return item['path'] === 'data/'}); const roots = cj['@graph'].filter((item) => {return item['path'] === 'data/'});
cjds = roots[0]; cjds = roots[0];
...@@ -138,16 +164,12 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { ...@@ -138,16 +164,12 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
it("has subjects", () => { it("has subjects", () => {
// FORs and SEOs // FORs and SEOs
const fields = [ 'dc:subject_anzsrc:for', 'dc:subject_anzsrc:seo']; const fields = [ 'dc:subject_anzsrc:for', 'dc:subject_anzsrc:seo'];
const SUBJECT_IRI_PREFIX = {
'dc:subject_anzsrc:for': '_:FOR/',
'dc:subject_anzsrc:seo': '_:SEO/'
};
const about = cjds['about'].map((i) => i['@id']); const about = cjds['about'].map((i) => i['@id']);
_.forEach(fields, (field) => { _.forEach(fields, (field) => {
const pref = SUBJECT_IRI_PREFIX[field]; const pref = IRI_PREFIXES['about'][field];
const expectsubs = dp[field].map((f) => { return f['name'] }); const expectsubs = dp[field].map((f) => f['name']);
const subjects = cj['@graph'].filter((i) => { return i['@id'].startsWith(pref) }); const gotsubs = get_id_prefix(cj, pref).map((f) => f['name']);
const gotsubs = subjects.map((f) => { return f['name']} );
if( dp[field] && dp[field].length > 0 ) { if( dp[field] && dp[field].length > 0 ) {
expect(gotsubs.sort()).to.eql(expectsubs.sort()); expect(gotsubs.sort()).to.eql(expectsubs.sort());
} else { } else {
...@@ -156,10 +178,33 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { ...@@ -156,10 +178,33 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
}) })
}); });
// geolocations - basic_name / latitude / longitude
// this test assumes that each geolocation's name is unique in the
// datapub
// and that geospatial is always a FeatureCollection
it("has spatial coverage", () => { it("has spatial coverage", () => {
assert(false); const spatials = get_id_prefix(cj, IRI_PREFIXES['spatialCoverage']);
if( dp['geoLocations'] ) {
dp['geoLocations'].map((gl) => {
const name = gl['basic_name'];
const matches = spatials.filter((s) => s['name'] === name );
expect(matches).to.have.lengthOf(1);
expect(matches[0]['latitude']).to.equal(gl['latitude']);
expect(matches[0]['longitude']).to.equal(gl['longitude']);
});
}
if( dp['geospatial']) {
const matches = spatials.filter((s) => s['@type'] === 'FeatureCollection' );
expect(matches).to.have.lengthOf(1);
expect(matches[0]['features']).to.eql(dp['geospatial']['features']);
}
}); });
it("has temporal coverage", () => { it("has temporal coverage", () => {
var tc = ''; var tc = '';
if( dp['startDate'] ) { if( dp['startDate'] ) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment