From 4df0f98b142a401caaf6c22784bb487bd8629b55 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Fri, 18 Sep 2015 16:24:00 -0400 Subject: [PATCH] Add type list, and raw mappings to/from source/layer and type --- helper/type_mapping.js | 78 ++++++++++++++++++++++++++++++++ test/unit/helper/type_mapping.js | 46 +++++++++++++++++++ test/unit/run.js | 1 + 3 files changed, 125 insertions(+) create mode 100644 helper/type_mapping.js create mode 100644 test/unit/helper/type_mapping.js diff --git a/helper/type_mapping.js b/helper/type_mapping.js new file mode 100644 index 00000000..0ac2a30d --- /dev/null +++ b/helper/type_mapping.js @@ -0,0 +1,78 @@ +var ALL_TYPES = [ + 'geoname', + 'osmnode', + 'osmway', + 'admin0', + 'admin1', + 'admin2', + 'neighborhood', + 'locality', + 'local_admin', + 'osmaddress', + 'openaddresses' +]; + +var TYPE_TO_SOURCE = { + 'geoname': 'gn', + 'osmnode': 'osm', + 'osmway': 'osm', + 'admin0': 'qs', + 'admin1': 'qs', + 'admin2': 'qs', + 'neighborhood': 'qs', + 'locality': 'qs', + 'local_admin': 'qs', + 'osmaddress': 'osm', + 'openaddresses': 'oa' +}; + +/* + * This doesn't include alias layers such as coarse + */ +var TYPE_TO_LAYER = { + 'geoname': 'venue', + 'osmnode': 'venue', + 'osmway': 'venue', + 'admin0': 'country', + 'admin1': 'region', + 'admin2': 'county', + 'neighborhood': 'neighbourhood', + 'locality': 'locality', + 'local_admin': 'localadmin', + 'osmaddress': 'address', + 'openaddresses': 'address' +}; + +var SOURCE_TO_TYPE = { + 'gn' : ['geoname'], + 'geonames' : ['geoname'], + 'oa' : ['openaddresses'], + 'openaddresses' : ['openaddresses'], + 'qs' : ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'], + 'quattroshapes' : ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'], + 'osm' : ['osmaddress', 'osmnode', 'osmway'], + 'openstreetmap' : ['osmaddress', 'osmnode', 'osmway'] +}; + +/** + * This includeds alias layers + */ +var LAYER_TO_TYPE = { + 'venue': ['geoname','osmnode','osmway'], + 'address': ['osmaddress','openaddresses'], + 'country': ['admin0'], + 'region': ['admin1'], + 'county': ['admin2'], + 'locality': ['locality'], + 'localadmin': ['local_admin'], + 'neighbourhood': ['neighborhood'], + 'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin'], +}; + +module.exports = { + types_list: ALL_TYPES, + type_to_source: TYPE_TO_SOURCE, + type_to_layer: TYPE_TO_LAYER, + source_to_type: SOURCE_TO_TYPE, + layer_to_type: LAYER_TO_TYPE +}; diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js new file mode 100644 index 00000000..1d1c945e --- /dev/null +++ b/test/unit/helper/type_mapping.js @@ -0,0 +1,46 @@ +var check = require('check-types'); +var type_mapping = require('../../../helper/type_mapping'); + +module.exports.tests = {}; + +module.exports.tests.interfaces = function(test, common) { + test('types_list', function(t) { + t.ok(check.array(type_mapping.types_list), 'is array'); + t.ok(check.hasLength(type_mapping.types_list, 11), 'has correct number of elements'); + t.end(); + }); + + test('type to source mapping', function(t) { + t.ok(check.object(type_mapping.type_to_source), 'is object'); + t.ok(check.hasLength(Object.keys(type_mapping.type_to_source), 11), 'has correct number of elements'); + t.end(); + }); + + test('type to layer mapping', function(t) { + t.ok(check.object(type_mapping.type_to_layer), 'is object'); + t.ok(check.hasLength(Object.keys(type_mapping.type_to_layer), 11), 'has correct number of elements'); + t.end(); + }); + + test('source to type mapping', function(t) { + t.ok(check.object(type_mapping.source_to_type), 'is object'); + t.ok(check.hasLength(Object.keys(type_mapping.source_to_type), 8), 'has correct number of elements'); + t.end(); + }); + + test('layer to type mapping', function(t) { + t.ok(check.object(type_mapping.layer_to_type), 'is object'); + t.ok(check.hasLength(Object.keys(type_mapping.layer_to_type), 9), 'has correct number of elements'); + t.end(); + }); +}; + +module.exports.all = function (tape, common) { + function test(name, testFunction) { + return tape('type_mapping: ' + name, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; diff --git a/test/unit/run.js b/test/unit/run.js index 50c301de..6b24259f 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -26,6 +26,7 @@ var tests = [ require('./helper/geojsonify'), require('./helper/outputSchema'), require('./helper/types'), + require('./helper/type_mapping'), require('./sanitiser/_geo_common'), require('./middleware/distance'), require('./middleware/confidenceScoreReverse'),