Browse Source

Merge branch 'master' into temp_ngrams_strip_housenumbers

temp_ngrams_strip_housenumbers
Peter Johnson 9 years ago
parent
commit
ed0354cbaf
  1. 4
      helper/geojsonify.js
  2. 35
      helper/labelGenerator.js
  3. 6
      helper/labelSchema.json
  4. 37
      helper/outputGenerator.js
  5. 2
      public/attribution.md
  6. 16
      query/defaults.js
  7. 4
      query/search.js
  8. 4
      test/unit/fixture/search_linguistic_bbox.js
  9. 4
      test/unit/fixture/search_linguistic_focus_bbox.js
  10. 228
      test/unit/helper/labelGenerator.js
  11. 2
      test/unit/helper/labelSchema.js
  12. 3
      test/unit/run.js

4
helper/geojsonify.js

@ -1,7 +1,7 @@
var GeoJSON = require('geojson'),
extent = require('geojson-extent'),
outputGenerator = require('./outputGenerator'),
labelGenerator = require('./labelGenerator'),
logger = require('pelias-logger').get('api'),
type_mapping = require('./type_mapping'),
_ = require('lodash');
@ -116,7 +116,7 @@ function addDetails(src, dst) {
* @param {object} dst
*/
function addLabel(src, dst) {
dst.label = outputGenerator(src);
dst.label = labelGenerator(src);
}
/**

35
helper/labelGenerator.js

@ -0,0 +1,35 @@
var _ = require('lodash'),
check = require('check-types'),
schemas = require('./labelSchema.json');
module.exports = function( record ){
var labelParts = [ record.name.default ];
var schema = schemas.default;
if (record.country_a && record.country_a.length && schemas[record.country_a]) {
schema = schemas[record.country_a];
}
var buildOutput = function(parts, schemaArr, record) {
for (var i=0; i<schemaArr.length; i++) {
var fieldValue = record[schemaArr[i]];
if (check.unemptyString(fieldValue) && !_.contains(parts, fieldValue)) {
parts.push( fieldValue );
return parts;
}
}
return parts;
};
for (var key in schema) {
labelParts = buildOutput(labelParts, schema[key], record);
}
// de-dupe outputs
labelParts = _.unique( labelParts );
return labelParts.join(', ').trim();
};

6
helper/outputSchema.json → helper/labelSchema.json

@ -4,7 +4,11 @@
"regional": ["region_a", "region", "country"]
},
"GBR": {
"local": ["neighbourhood", "county", "localadmin", "locality"],
"local": ["neighbourhood", "county", "localadmin", "locality", "region"],
"regional": ["county","country","region"]
},
"SGP": {
"local": ["neighbourhood", "region", "county", "localadmin", "locality"],
"regional": ["county","country","region"]
},
"default": {

37
helper/outputGenerator.js

@ -1,37 +0,0 @@
var schemas = require('./outputSchema.json');
module.exports = function( record ){
var adminParts = [];
var schema = schemas.default;
if (record.country_a && record.country_a.length && schemas[record.country_a]) {
schema = schemas[record.country_a];
}
var buildOutput = function(parts, schemaArr, record) {
for (var i=0; i<schemaArr.length; i++) {
var rec = record[schemaArr[i]];
if (rec && rec.length) {
parts.push( rec );
return parts;
}
}
return parts;
};
for (var key in schema) {
adminParts = buildOutput(adminParts, schema[key], record);
}
var outputs = [ record.name.default ].concat( adminParts );
// de-dupe outputs
outputs = outputs.filter( function( i, pos ) {
return outputs.indexOf( i ) === pos;
});
return outputs.join(', ').trim();
};

2
public/attribution.md

@ -2,6 +2,6 @@
* Geocoding by [Pelias](https://mapzen.com/pelias) from [Mapzen](https://mapzen.com)
* Data from
* [OpenStreetMap](http://www.openstreetmap.org/copyright) © OpenStreetMap contributors under [ODbL](http://opendatacommons.org/licenses/odbl/)
* [OpenAddresses](http://openaddresses.io) under a [Creative Commons Zero](https://github.com/openaddresses/openaddresses/blob/master/sources/LICENSE) public domain designation
* [Quattroshapes](https://github.com/foursquare/quattroshapes/blob/master/LICENSE.md) under [CC-BY-2.0](https://creativecommons.org/licenses/by/2.0/)
* [GeoNames](http://www.geonames.org/) under [CC-BY-3.0](https://creativecommons.org/licenses/by/2.0/)
* and other sources

16
query/defaults.js

@ -39,35 +39,35 @@ module.exports = extend( false, peliasQuery.defaults, {
'address:housenumber:analyzer': 'standard',
'address:housenumber:field': 'address.number',
'address:housenumber:boost': 1,
'address:housenumber:boost': 2,
'address:street:analyzer': 'standard',
'address:street:field': 'address.street',
'address:street:boost': 1,
'address:street:boost': 5,
'address:postcode:analyzer': 'standard',
'address:postcode:field': 'address.zip',
'address:postcode:boost': 1,
'address:postcode:boost': 3,
'admin:alpha3:analyzer': 'standard',
'admin:alpha3:field': 'alpha3',
'admin:alpha3:boost': 1,
'admin:alpha3:boost': 5,
'admin:admin0:analyzer': 'peliasAdmin',
'admin:admin0:field': 'admin0',
'admin:admin0:boost': 1,
'admin:admin0:boost': 4,
'admin:admin1:analyzer': 'peliasAdmin',
'admin:admin1:field': 'admin1',
'admin:admin1:boost': 1,
'admin:admin1:boost': 3,
'admin:admin1_abbr:analyzer': 'peliasAdmin',
'admin:admin1_abbr:field': 'admin1_abbr',
'admin:admin1_abbr:boost': 1,
'admin:admin1_abbr:boost': 3,
'admin:admin2:analyzer': 'peliasAdmin',
'admin:admin2:field': 'admin2',
'admin:admin2:boost': 1,
'admin:admin2:boost': 2,
'admin:local_admin:analyzer': 'peliasAdmin',
'admin:local_admin:field': 'local_admin',

4
query/search.js

@ -86,9 +86,9 @@ function generateQuery( clean ){
check.number(clean['boundary.rect.min_lon']) &&
check.number(clean['boundary.rect.max_lon']) ){
vs.set({
'boundary:rect:top': clean['boundary.rect.min_lat'],
'boundary:rect:top': clean['boundary.rect.max_lat'],
'boundary:rect:right': clean['boundary.rect.max_lon'],
'boundary:rect:bottom': clean['boundary.rect.max_lat'],
'boundary:rect:bottom': clean['boundary.rect.min_lat'],
'boundary:rect:left': clean['boundary.rect.min_lon']
});
}

4
test/unit/fixture/search_linguistic_bbox.js

@ -73,9 +73,9 @@ module.exports = {
'must': [{
'geo_bounding_box': {
'center_point': {
'top': 47.47,
'top': 11.51,
'right': -61.84,
'bottom': 11.51,
'bottom': 47.47,
'left': -103.16
},
'_cache': true,

4
test/unit/fixture/search_linguistic_focus_bbox.js

@ -102,9 +102,9 @@ module.exports = {
'must': [{
'geo_bounding_box': {
'center_point': {
'top': 47.47,
'top': 11.51,
'right': -61.84,
'bottom': 11.51,
'bottom': 47.47,
'left': -103.16
},
'_cache': true,

228
test/unit/helper/labelGenerator.js

@ -0,0 +1,228 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
// major USA city
module.exports.tests.san_francisco = function(test, common) {
test('san francisco', function(t) {
var doc = {
'name': { 'default': 'San Francisco' },
'country_a': 'USA',
'country': 'United States',
'region': 'California',
'region_a': 'CA',
'county': 'San Francisco County',
'locality': 'San Francisco'
};
t.equal(generator(doc),'San Francisco, San Francisco County, CA');
t.end();
});
};
// USA venue
module.exports.tests.nyc_office = function(test, common) {
test('30 West 26th Street', function(t) {
var doc = {
'name': { 'default': '30 West 26th Street' },
'housenumber': '30',
'street': 'West 26th Street',
'postalcode': '10010',
'country_a': 'USA',
'country': 'United States',
'region': 'New York',
'region_a': 'NY',
'county': 'New York County',
'localadmin': 'Manhattan',
'locality': 'New York',
'neighbourhood': 'Flatiron District'
};
t.equal(generator(doc),'30 West 26th Street, Manhattan, NY');
t.end();
});
};
// AUS state
module.exports.tests.new_south_wales = function(test, common) {
test('new south wales', function(t) {
var doc = {
'name': { 'default': 'New South Wales' },
'country_a': 'AUS',
'country': 'Australia',
'region': 'New South Wales'
};
t.equal(generator(doc),'New South Wales, Australia');
t.end();
});
};
// USA state
module.exports.tests.california = function(test, common) {
test('california', function(t) {
var doc = {
'name': { 'default': 'California' },
'country_a': 'USA',
'country': 'United States',
'region': 'California',
'region_a': 'CA'
};
t.equal(generator(doc),'California, CA');
t.end();
});
};
// IND state
module.exports.tests.west_bengal = function(test, common) {
test('west bengal', function(t) {
var doc = {
'name': { 'default': 'West Bengal' },
'country_a': 'IND',
'country': 'India',
'region': 'West Bengal'
};
t.equal(generator(doc),'West Bengal, India');
t.end();
});
};
// SGP region
module.exports.tests.north_west_singapore = function(test, common) {
test('north west singapore', function(t) {
var doc = {
'name': { 'default': 'North West' },
'country_a': 'SGP',
'country': 'Singapore',
'region': 'North West'
};
t.equal(generator(doc),'North West, Singapore');
t.end();
});
};
// IRQ region
module.exports.tests.arbil = function(test, common) {
test('arbil', function(t) {
var doc = {
'name': { 'default': 'Arbil' },
'country_a': 'IRQ',
'country': 'Iraq',
'region': 'Arbil'
};
t.equal(generator(doc),'Arbil, Iraq');
t.end();
});
};
// ESP city
module.exports.tests.madrid = function(test, common) {
test('madrid', function(t) {
var doc = {
'name': { 'default': 'Madrid' },
'country_a': 'ESP',
'country': 'Spain',
'region': 'Madrid'
};
t.equal(generator(doc),'Madrid, Spain');
t.end();
});
};
// GBR street address
module.exports.tests.one_main_street_uk = function(test, common) {
test('one main street uk', function(t) {
var doc = {
'name': { 'default': '1 Main St' },
'housenumber': '1',
'street': 'Main St',
'postalcode': 'BT77 0BG',
'country_a': 'GBR',
'country': 'United Kingdom',
'region': 'Dungannon'
};
t.equal(generator(doc),'1 Main St, Dungannon, United Kingdom');
t.end();
});
};
// GBR venue
module.exports.tests.hackney_city_farm = function(test, common) {
test('hackney city farm', function(t) {
var doc = {
'name': { 'default': 'Hackney City Farm' },
'country_a': 'GBR',
'country': 'United Kingdom',
'region': 'Hackney',
'county': 'Greater London',
'locality': 'London',
'neighbourhood': 'Haggerston'
};
t.equal(generator(doc),'Hackney City Farm, Haggerston, Greater London');
t.end();
});
};
// DEU street address
module.exports.tests.one_grolmanstrasse = function(test, common) {
test('one grolmanstrasse', function(t) {
var doc = {
'name': { 'default': '1 Grolmanstraße' },
'housenumber': '1',
'street': 'Grolmanstraße',
'postalcode': '10623',
'country_a': 'DEU',
'country': 'Germany',
'region': 'Berlin',
'county': 'Berlin',
'locality': 'Berlin',
'neighbourhood': 'Halensee'
};
t.equal(generator(doc),'1 Grolmanstraße, Berlin, Germany');
t.end();
});
};
// NZD country
module.exports.tests.new_zealand = function(test, common) {
test('new zealand', function(t) {
var doc = {
'name': { 'default': 'New Zealand' },
'country_a': 'NZL',
'country': 'New Zealand'
};
t.equal(generator(doc),'New Zealand');
t.end();
});
};
// SGP venue
module.exports.tests.singapore_mcdonalds = function(test, common) {
test('singapore_mcdonalds', function(t) {
var doc = {
'name': { 'default': 'McDonald\'s' },
'country_a': 'SGP',
'country': 'Singapore',
'region': 'Central Singapore',
'locality': 'Singapore'
};
t.equal(generator(doc),'McDonald\'s, Central Singapore, Singapore');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

2
test/unit/helper/outputSchema.js → test/unit/helper/labelSchema.js

@ -1,5 +1,5 @@
var schemas = require('../../../helper/outputSchema.json');
var schemas = require('../../../helper/labelSchema.json');
var alpha3 = require('../mock/alpha3.json');
module.exports.tests = {};

3
test/unit/run.js

@ -24,7 +24,8 @@ var tests = [
require('./query/view/temp_ngrams_strip_housenumbers'),
require('./helper/query_parser'),
require('./helper/geojsonify'),
require('./helper/outputSchema'),
require('./helper/labelSchema'),
require('./helper/labelGenerator'),
require('./helper/types'),
require('./helper/type_mapping'),
require('./sanitiser/_geo_common'),

Loading…
Cancel
Save