pelias / model

Pelias data models
6 stars 17 forks source link

add post processing script to handle separable street names #119

Closed missinglink closed 5 years ago

missinglink commented 5 years ago

add post processing script to generate expanded and contracted forms of compound street names

This is a PR I've been wanting to do for a while now, it generates aliases for contracted/expanded forms of street names.

missinglink commented 5 years ago

Similar to https://github.com/pelias/openaddresses/blob/af097099482b77bd0b13cc3e9af7f251dd1691ee/lib/streams/germanicAbbreviationStream.js although it uses aliases to index all possible forms rather than simply expanding.

orangejulius commented 5 years ago

Nice, so this would fix https://github.com/pelias/pelias/issues/555, right?

missinglink commented 5 years ago

Yep

orangejulius commented 5 years ago

I tried to test this today. On my machine at least, using the seperable_street_names branch with the OSM or OA importer causes the importer to hang.

This would be nice to test and merge if we get a chance to revisit it.

missinglink commented 5 years ago

oh nice catch, I fixed it up and rebased it, the diff was:

diff --git a/Document.js b/Document.js
index 3426df3..ce1ff15 100644
--- a/Document.js
+++ b/Document.js
@@ -81,8 +81,13 @@ Document.prototype.toJSON = function(){
  */
 Document.prototype.toESDocument = function() {

-  // call all post-processing scripts
-  this.callPostProcessingScripts();
+  try {
+    // call all post-processing scripts
+    this.callPostProcessingScripts();
+  } catch (e) {
+    console.error('a post processing error occurred');
+    console.error(e);
+  }

   var doc = {
     name: this.name,
diff --git a/post/seperable_street_names.js b/post/seperable_street_names.js
index 00b0dce..84f17b9 100644
--- a/post/seperable_street_names.js
+++ b/post/seperable_street_names.js
@@ -77,7 +77,7 @@ function post(doc) {
   if( !TARGET_LAYERS.includes( doc.getLayer() ) ) { return; }

   // detect document country code
-  let docCountryCode = doc.parent.country_a[0];
+  let docCountryCode = _.get(doc, 'parent.country_a[0]');
   if( !_.isString(docCountryCode) || docCountryCode.length !== 3 ) { return; }
missinglink commented 5 years ago

Fixed another bug, turns out real-world data is messy, who would have thought 🤷‍♂

missinglink commented 5 years ago

I tested this out and it works well now, good to merge.