How to use pelias-model - 10 common examples

To help you get started, we’ve selected a few pelias-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pelias / openstreetmap / test / stream / category_mapper.js View on Github external
module.exports.tests.sport_wildcard = function(test, common) {
  var doc = new Document('osm','a',1);
  doc.setMeta( 'tags', { 'sport': 'rugby_union' } );
  test('maps - sports inherit recreation via wildcard', function(t) {
    var stream = mapper( defaultMapping );
    stream.pipe( through.obj( function( doc, enc, next ){
      t.deepEqual(doc.category, ['recreation','entertainment'], 'correctly mapped');
      t.end(); // test will fail if not called (or called twice).
      next();
    }));
    stream.write(doc);
  });
};
github pelias / openstreetmap / test / stream / address_extractor.js View on Github external
test('errors - catch thrown errors', function(t) {
    var doc = new Document('a','b', 1);

    // this method will throw a generic Error for testing
    doc.getLayer = function(){ throw new Error('test'); };

    test_stream([doc], extractor(), function( err, actual ) {
      t.equal(actual.length, 0, 'no results');
      t.end();
    });
  });
github pelias / openstreetmap / test / stream / category_mapper.js View on Github external
test('errors - catch thrown errors', function(t) {
    var doc = new Document('osm','a',1);

    // this method will throw a generic Error for testing
    doc.getMeta = function(){ throw new Error('test'); };

    var stream = mapper();
    stream.pipe( through.obj( function( doc, enc, next ){
      t.deepEqual( doc.getLayer(), 'a', 'doc passthrough' );
      t.end(); // test will fail if not called (or called twice).
      next();
    }));
    stream.write(doc);
  });
};
github pelias / openstreetmap / test / stream / popularity_mapper.js View on Github external
module.exports.tests.international_airport = function(test, common) {
  var doc = new Document('a','venue',1);
  doc.setMeta('tags', { 'aerodrome': 'international', 'iata': 'JFK' });
  test('alias - international airport', function(t) {
    var stream = mapper();
    stream.pipe( through.obj( function( doc, enc, next ){
      t.deepEqual(doc.getPopularity(), 15000);
      t.end(); // test will fail if not called (or called twice).
      next();
    }));
    stream.write(doc);
  });
};
github pelias / openstreetmap / test / stream / popularity_mapper.js View on Github external
module.exports.tests.nonvenue = function (test, common) {
  var doc = new Document('osm', 'address', 1);
  doc.setMeta('tags', { 'importance': 'international' });
  test('does not map - non-venue', t => {
    var stream = mapper();
    stream.pipe(through.obj((doc, enc, next) => {
      t.false(doc.getPopularity(), 'no mapping performed');
      t.end(); // test will fail if not called (or called twice).
      next();
    }));
    stream.write(doc);
  });
};
github pelias / api / test / unit / helper / geojsonify.js View on Github external
const geojsonify = require('../../../helper/geojsonify');
const proxyquire = require('proxyquire').noCallThru();
const codec = require('pelias-model').codec;

module.exports.tests = {};

module.exports.tests.interface = function(test, common) {
  test('valid interface', function(t) {
    t.equal(typeof geojsonify, 'function', 'geojsonify is a function');
    t.equal(geojsonify.length, 2, 'accepts x arguments');
    t.end();
  });
};

// ensure null island coordinates work
// ref: https://github.com/pelias/pelias/issues/84
module.exports.tests.earth = function(test, common) {
  test('earth', function(t) {
    var earth = [{
github pelias / openstreetmap / test / fixtures / docs.js View on Github external
docs.completeDoc = new Document('osm','venue','item:6');
docs.completeDoc.address_parts = {
  number: '13', street: 'Goldsmiths row', test: 'prop'
};
docs.completeDoc
  .setName('default','item6')
  .setName('alt','item six')
  .setCentroid({lat:6,lon:6})
  .setMeta('foo','bar')
  .setMeta('bing','bang');

docs.osmNode1 = new Document('osm','venue','item:7')
  .setName('node','node7')
  .setCentroid({lat:7,lon:7});

docs.osmWay1 = new Document('osm','venue','way:8')
  .setName('way','way8')
  .setMeta('nodes', [
    { lat: 10, lon: 10 },
    { lat: 06, lon: 10 },
    { lat: 06, lon: 06 },
    { lat: 10, lon: 06 }
  ]);

docs.osmRelation1 = new Document('osm','venue','item:9')
  .setName('relation','relation9')
  .setCentroid({lat:9,lon:9});

// ref: https://github.com/pelias/openstreetmap/issues/21
docs.semicolonStreetNumbers = new Document('osm','venue','item:10');
docs.semicolonStreetNumbers.setName('default','poi10');
docs.semicolonStreetNumbers.setCentroid({lat:10,lon:10});
github pelias / openstreetmap / test / stream / document_constructor.js View on Github external
stream.pipe( through.obj( function( doc, enc, next ){
      t.equal( Object.getPrototypeOf(doc), Document.prototype, 'correct proto' );
      t.equal( doc.getId(), 'X/1', 'correct id' );
      t.equal( doc.getLayer(), 'venue', 'defaults to venue' );
      t.end(); // test will fail if not called (or called twice).
      next();
    }));
    stream.write({ id: 1, type: 'X' });
github pelias / whosonfirst / src / peliasDocGenerators.js View on Github external
function setupDocument(record, hierarchy) {
  var wofDoc = new Document( 'whosonfirst', record.place_type, record.id );

  if (record.name) {
    wofDoc.setName('default', record.name);

    // index a version of postcode which doesn't contain whitespace
    if (record.place_type === 'postalcode' && typeof record.name === 'string') {
      var sans_whitespace = record.name.replace(/\s/g, '');
      if (sans_whitespace !== record.name) {
        wofDoc.setNameAlias('default', sans_whitespace);
      }
    }

    // index name aliases for all other records (where available)
    else {
      if (record.name_aliases.length) {
        record.name_aliases.forEach(alias => {
github pelias / api / helper / geojsonify.js View on Github external
function geojsonifyPlace(params, place) {
  const gid_components = decode_gid(place._id);
  // setup the base doc
  const doc = {
    id: gid_components.id,
    gid: new Document(place.source, place.layer, gid_components.id).getGid(),
    layer: place.layer,
    source: place.source,
    source_id: gid_components.id,
    bounding_box: place.bounding_box,
    lat: parseFloat(place.center_point.lat),
    lng: parseFloat(place.center_point.lon)
  };

  // assign name, logging a warning if it doesn't exist
  if (_.has(place, 'name.default')) {
    doc.name = field.getStringValue(place.name.default);
  } else {
    logger.warn(`doc ${doc.gid} does not contain name.default`);
  }

  // assign all the details info into the doc