Skip to content

Commit

Permalink
update pipeline for vn translations
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgrossman committed Sep 24, 2017
1 parent 4886f8f commit 7d23125
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
22 changes: 8 additions & 14 deletions js/insert-into-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ function insertIntoTable (feature, admin, st, db) {
if (!properties.en_name) {
properties.en_name = '...'
}
var t;
return db.transaction((t) => {
return db('admin_boundaries')
.transacting(t)
db.transaction((t) => {
return t
.insert({
// shared identifier for each row in admin table
type: admin,
Expand All @@ -86,16 +84,12 @@ function insertIntoTable (feature, admin, st, db) {
// english name of admin unit
name_en: properties.en_name,
// vietnamese name of admin unit
name_vn: ''
})
.then(t.commit)
.catch((e) => {
t.rollback();
throw e;
name_vn: properties.vn_name
})
.into('admin_boundaries')
.then(() => {console.log(new Date())})
})
.then(r => {})
.catch((e) => {
throw e;vim
})
}
console.log(e);
});
};
23 changes: 16 additions & 7 deletions js/simplify-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var parser = geojsonStream.parse();
var stringifier = geojsonStream.stringify();
// module to read path
var path = require('path');
// parallel allows for reading each admin geojson stream asynchronously
var parallel = require('async').parallel;
// since the output of `c-update-geojson-spec.sh` writes geojsons to a single line, the stream needs to be broken up into lines, otherwise it will not work
// split is a module that does just this.
var split = require('split');
Expand All @@ -26,7 +24,7 @@ writeSimplifiedProps(admin);

/**
* simplifies input properties to spec needed to make admin postgis tables
*
* @func makeNewProperties
* @param {object} properties original properties from streaming geojson
* @param {string} admin admin unit name, like 'commune', 'district,'
* @return {object} newProperties simplified properties generated from properties
Expand All @@ -35,22 +33,27 @@ function makeNewProperties (properties, admin) {
const newProperties = {};
if (new RegExp(/commune/).test(admin)) {
newProperties.en_name = properties.EN_name
newProperties.vn_name = properties.COMNAME_1
newProperties.id = properties.COMCODE02;
newProperties.p_id = properties.DISTCODE02
} else if (new RegExp(/district/).test(admin)) {
newProperties.en_name = properties.D_EName
newProperties.vn_name = properties.DISTNAME_
newProperties.id = properties.DISTCODE02
newProperties.p_id = properties.PROCODE02
} else if (new RegExp(/province/).test(admin)) {
newProperties.en_name = properties.P_EName
newProperties.vn_name = properties.PRONAME_1
newProperties.id = properties.PROCODE02
}
newProperties.en_name = cleanName(newProperties.en_name, admin);
newProperties.vn_name = cleanName(newProperties.vn_name, admin);
return newProperties;
}

/**
* reads in raw geojson and writes out simplified geojson for provided admin level
* @func writeSimplifiedProps
* @param {string} admin string representation of admin type
*
*/
Expand Down Expand Up @@ -79,18 +82,23 @@ function writeSimplifiedProps(adminPath) {

/**
* returns cleaned version of place name
* @func cleanName
* @param {string} name admin unit name
* @return {string} cleaned admin unit name
*/
function cleanName(name, admin) {
let cleanName = name;
let cleanName;
if (name) {
if (new RegExp(/X. /).test(name)) {
cleanName = name.replace('X. ','');
} else if (new RegExp(/P. /).test(name)) {
cleanName = name.replace('P. ', '')
} else if (new RegExp(/Tt. /).test(name)) {
cleanName = name.replace('Tt. ', '')
cleanName = name.replace('Tt. ', '')
} else if (new RegExp(/TP./).test(name)) {
cleanName = name.replace(/TP./, '')
if (new RegExp(/Ho Chi M/)) { cleanName = cleanName + `in`}
if (new RegExp(/Phon/)) { cleanName = cleanName + `g`}
} else if (new RegExp(/P. /).test(name)) {
cleanName = name.replace('P. ', '')
} else if (new RegExp(/ D./).test(name)){
Expand All @@ -101,6 +109,7 @@ function cleanName(name, admin) {
if (Boolean(Number(cleanName))) {
cleanName = `${admin} ${cleanName}`
}
}
return cleanName
cleanName = cleanName.trim();
} else { cleanName = ''}
return cleanName;
}

0 comments on commit 7d23125

Please sign in to comment.