mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
The exclusion tested the provenance after it was cut to 80 characters, so a long source list ending in wrecksite.eu kept the row, and a row whose only trace was a wrecksite.eu page link was kept too. Both raw values are now checked before anything is cut.
225 lines
7.1 KiB
JavaScript
225 lines
7.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
mergeShipwreckRecords,
|
|
normalizeEmodnetFeatures,
|
|
normalizeShipwreckSnapshot,
|
|
normalizeWikidataResults,
|
|
parseYear,
|
|
} from './records.js';
|
|
|
|
function feature(id, properties, coordinates = [-4.35, 54.13]) {
|
|
return {
|
|
type: 'Feature',
|
|
id,
|
|
geometry: { type: 'Point', coordinates },
|
|
properties,
|
|
};
|
|
}
|
|
|
|
test('EMODnet wrecks keep ship facts and drop text that names people', () => {
|
|
const [wreck, roman] = normalizeEmodnetFeatures({
|
|
features: [
|
|
feature('w.1', {
|
|
name: 'MAINA-NUI',
|
|
sink_yr: '1987',
|
|
sink_context: 'Sank on 07/02/1987',
|
|
obj_type: 'Pusher or tug',
|
|
least_depth: 12.5,
|
|
depth_prec: 'Least depth known',
|
|
loc_prec: 50,
|
|
country: 'France',
|
|
source_inf: 'SHOM',
|
|
statutory: 'n/a',
|
|
website1: 'n/a',
|
|
}),
|
|
feature('w.2', {
|
|
name: 'Lerici',
|
|
sink_yr: '',
|
|
dating: 'C1st-2nd AD',
|
|
period: 'Roman Imperial',
|
|
artefacts: 'Marble, Columns',
|
|
obj_type: 'n/a',
|
|
ship_char: 'Owned by J. Smith, master was A. Jones',
|
|
sink_context: 'Wrecked here, reported by Mr Smith',
|
|
}),
|
|
feature('w.3', { name: 'Copied', source_inf: 'www.wrecksite.eu' }),
|
|
feature('w.4', { name: 'Null island' }, [0, 0]),
|
|
],
|
|
});
|
|
const ids = normalizeEmodnetFeatures({
|
|
features: [
|
|
feature('w.3', { name: 'Copied', source_inf: 'www.wrecksite.eu' }),
|
|
feature('w.5', {
|
|
source_inf: `${'SHOM; '.repeat(20)}wrecksite.eu`,
|
|
}),
|
|
feature('w.6', { website1: 'https://www.wrecksite.eu/wreck.aspx?1' }),
|
|
feature('w.7', { website1: 'wrecksite.eu/wreck/1' }),
|
|
feature('w.8', { name: 'Kept', source_inf: 'SHOM' }),
|
|
],
|
|
}).map((record) => record.id);
|
|
assert.deepEqual(ids, ['emodnet:w.8'], 'wrecksite.eu rows are all skipped');
|
|
assert.equal(wreck.id, 'emodnet:w.1');
|
|
assert.equal(wreck.year, 1987);
|
|
assert.equal(wreck.vesselType, 'Pusher or tug');
|
|
assert.equal(wreck.cause, 'Sank on 07/02/1987');
|
|
assert.equal(wreck.depth, 12.5);
|
|
assert.equal(wreck.positionAccuracy, 50);
|
|
assert.equal(wreck.url, null);
|
|
assert.equal(roman.year, null);
|
|
assert.equal(roman.ancient, true);
|
|
assert.equal(roman.dating, 'C1st-2nd AD');
|
|
assert.equal(roman.notes, 'Roman Imperial (C1st-2nd AD)');
|
|
assert.equal(roman.cargo, 'Marble, Columns');
|
|
assert.equal(roman.vesselType, null, 'a history naming people is no type');
|
|
assert.equal(roman.cause, null, 'text naming a person is dropped');
|
|
});
|
|
|
|
test('Wikidata rows fold into one record per item', () => {
|
|
const item = 'http://www.wikidata.org/entity/Q1471525';
|
|
const records = normalizeWikidataResults({
|
|
results: {
|
|
bindings: [
|
|
{
|
|
item: { value: item },
|
|
itemLabel: { value: 'HMS Havant' },
|
|
itemDescription: { value: '1939 G and H-class destroyer' },
|
|
coord: { value: 'Point(2.26 51.13)' },
|
|
sunk: { value: '1940-06-01T00:00:00Z' },
|
|
enwiki: { value: 'https://en.wikipedia.org/wiki/HMS_Havant_(H32)' },
|
|
},
|
|
{
|
|
item: { value: item },
|
|
typeLabel: { value: 'destroyer' },
|
|
deaths: { value: '8' },
|
|
coord: { value: 'Point(2.26 51.13)' },
|
|
},
|
|
{
|
|
item: { value: 'http://www.wikidata.org/entity/Q9' },
|
|
itemLabel: { value: 'Q9' },
|
|
coord: { value: 'Point(10 10)' },
|
|
},
|
|
],
|
|
},
|
|
});
|
|
assert.equal(records.length, 2);
|
|
const [havant, unnamed] = records;
|
|
assert.equal(havant.date, '1940-06-01');
|
|
assert.equal(havant.year, 1940);
|
|
assert.equal(havant.vesselType, 'destroyer');
|
|
assert.equal(havant.casualties, 8);
|
|
assert.equal(havant.url, 'https://en.wikipedia.org/wiki/HMS_Havant_(H32)');
|
|
assert.equal(unnamed.name, null);
|
|
assert.equal(unnamed.url, 'https://www.wikidata.org/wiki/Q9');
|
|
});
|
|
|
|
test('a wreck in both sources keeps Wikidata and takes EMODnet survey facts', () => {
|
|
const wikidata = [
|
|
{
|
|
id: 'wikidata:Q1',
|
|
source: 'wikidata',
|
|
name: 'HMS Havant',
|
|
lat: 51.13,
|
|
lon: 2.26,
|
|
year: null,
|
|
depth: null,
|
|
},
|
|
];
|
|
const emodnet = [
|
|
{
|
|
id: 'emodnet:a',
|
|
source: 'emodnet',
|
|
name: 'Havant (HMS)',
|
|
lat: 51.131,
|
|
lon: 2.262,
|
|
year: 1940,
|
|
depth: 14.7,
|
|
},
|
|
{
|
|
id: 'emodnet:b',
|
|
source: 'emodnet',
|
|
name: 'HMS Havant',
|
|
lat: 45,
|
|
lon: -10,
|
|
year: 1950,
|
|
},
|
|
];
|
|
const merged = mergeShipwreckRecords(emodnet, wikidata);
|
|
assert.deepEqual(
|
|
merged.map((record) => record.id),
|
|
['wikidata:Q1', 'emodnet:b'],
|
|
);
|
|
assert.equal(merged[0].year, 1940);
|
|
assert.equal(merged[0].depth, 14.7);
|
|
assert.equal(merged[0].alsoIn, 'emodnet');
|
|
});
|
|
|
|
test('years and snapshots are validated', () => {
|
|
assert.equal(parseYear('1917-1918'), 1917);
|
|
assert.equal(parseYear('c. 1588'), 1588);
|
|
assert.equal(parseYear(''), null);
|
|
assert.equal(parseYear('3000'), null);
|
|
assert.equal(normalizeShipwreckSnapshot({}), null);
|
|
const rows = normalizeShipwreckSnapshot({
|
|
records: [
|
|
{ id: 'a', source: 'emodnet', lat: 1, lon: 2, url: 'javascript:x' },
|
|
{ id: 'a', source: 'emodnet', lat: 1, lon: 2 },
|
|
{ id: 'b', source: 'other', lat: 1, lon: 2 },
|
|
{ id: 'c', source: 'wikidata', lat: 91, lon: 2 },
|
|
],
|
|
});
|
|
assert.equal(rows.length, 1);
|
|
assert.equal(rows[0].url, null);
|
|
});
|
|
|
|
test('a sinking event folds into its ship; month-precise dates keep the year only', () => {
|
|
const entity = (q) => ({ value: `http://www.wikidata.org/entity/${q}` });
|
|
const records = normalizeWikidataResults({
|
|
results: {
|
|
bindings: [
|
|
{
|
|
item: entity('Q25173'),
|
|
itemLabel: { value: 'Titanic' },
|
|
coord: { value: 'Point(-49.9469 41.7325)' },
|
|
},
|
|
{
|
|
item: entity('Q3018259'),
|
|
itemLabel: { value: 'wreck of the RMS Titanic' },
|
|
coord: { value: 'Point(-49.9469 41.7325)' },
|
|
},
|
|
{
|
|
item: entity('Q2577588'),
|
|
itemLabel: { value: 'sinking of the RMS Titanic' },
|
|
coord: { value: 'Point(-49.9458 41.7319)' },
|
|
event: { value: 'event' },
|
|
sunk: { value: '1912-04-01T00:00:00Z' },
|
|
sunkPrecision: { value: '10' },
|
|
deaths: { value: '1501' },
|
|
survivors: { value: '712' },
|
|
},
|
|
{
|
|
item: entity('Q1245004'),
|
|
itemLabel: { value: 'Costa Concordia disaster' },
|
|
coord: { value: 'Point(10.92 42.37)' },
|
|
event: { value: 'event' },
|
|
sunk: { value: '2012-01-13T00:00:00Z' },
|
|
sunkPrecision: { value: '11' },
|
|
deaths: { value: '32' },
|
|
},
|
|
],
|
|
},
|
|
});
|
|
assert.deepEqual(
|
|
records.map((record) => record.id),
|
|
['wikidata:Q25173', 'wikidata:Q1245004'],
|
|
);
|
|
const [titanic, concordia] = records;
|
|
assert.equal(titanic.date, null);
|
|
assert.equal(titanic.year, 1912);
|
|
assert.equal(titanic.casualties, 1501);
|
|
assert.equal(titanic.survivors, 712);
|
|
assert.equal(concordia.name, 'Costa Concordia disaster');
|
|
assert.equal(concordia.date, '2012-01-13');
|
|
assert.equal('event' in concordia, false);
|
|
});
|