pelias / model

Pelias data models
6 stars 17 forks source link

support common intersection syntactic variations #111

Closed missinglink closed 5 years ago

missinglink commented 5 years ago

This PR improves support for intersection matching in Pelias.

It introduces a new layer called intersection as well as a new address_parts property called cross_street.

I've also added a new concept within the pelias/model code which allow registering of "post-processing scripts" which are executed within the toESDocument function before being converted to the ES schema format.

The post/intersections.js function I've added detects documents from the intersection layer and adds additional name aliases as such:

  // corner of A & B
  doc.setNameAlias('default', `${street} & ${cross_street}`);
  doc.setNameAlias('default', `${street} @ ${cross_street}`);
  doc.setNameAlias('default', `${street} at ${cross_street}`);
  doc.setNameAlias('default', `Corner of ${street} & ${cross_street}`);

  // corner of B & A
  doc.setNameAlias('default', `${cross_street} & ${street}`);
  doc.setNameAlias('default', `${cross_street} @ ${street}`);
  doc.setNameAlias('default', `${cross_street} at ${street}`);
  doc.setNameAlias('default', `Corner of ${cross_street} & ${street}`);

There are a few changes here so I'd appreciate some feedback before merging this. We discussed other places in the codebase where this code might live but in the end, decided that it would be nice to have it in pelias/model so it can be used by any importer.

Intersection queries pose a few different issues, this PR will help improve the syntactic matching using name aliases, but it might be beneficial to address any vocab related issue in a pelias/schema PR (such as at vs @ and other common punctuation variations).

WIP: waiting for feedback, requires more unit tests to cover all functionality in PR (such as the 3 new methods on Document)

missinglink commented 5 years ago

I just added some unit tests for the 3 new methods on Document.

In the process I decided to change the way the doc pointer is passed to the scripts, instead of setting it as $this I'm now passing it as the first argument, this is just less-fancy, more predictable and avoids unexpected behaviour when using arrow functions.

I've also added a couple additional assertions here-and-there.

Removed WIP label, happy to merge this code as-is @orangejulius.

missinglink commented 5 years ago

rebased master to resolve merge conflict.