Browse Source

Add type list, and raw mappings to/from source/layer and type

pull/292/head
Julian Simioni 9 years ago
parent
commit
4df0f98b14
  1. 78
      helper/type_mapping.js
  2. 46
      test/unit/helper/type_mapping.js
  3. 1
      test/unit/run.js

78
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
};

46
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);
}
};

1
test/unit/run.js

@ -26,6 +26,7 @@ var tests = [
require('./helper/geojsonify'), require('./helper/geojsonify'),
require('./helper/outputSchema'), require('./helper/outputSchema'),
require('./helper/types'), require('./helper/types'),
require('./helper/type_mapping'),
require('./sanitiser/_geo_common'), require('./sanitiser/_geo_common'),
require('./middleware/distance'), require('./middleware/distance'),
require('./middleware/confidenceScoreReverse'), require('./middleware/confidenceScoreReverse'),

Loading…
Cancel
Save