Created
May 22, 2017 10:56
-
-
Save tvararu/0d5db12d2913647e9b4da07b7b330b51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to run: | |
// 1. Change PATH_TO_GRAPH | |
// 2. Run `node graph2tsv.js` | |
const fs = require('fs') | |
const PATH_TO_GRAPH = './location-etd.json' | |
const PATH_TO_TSV = PATH_TO_GRAPH.replace('.json', '.tsv') | |
const graph = require(PATH_TO_GRAPH) | |
const header = [ | |
'Key', | |
'English name', | |
'Welsh name', | |
'Canonical', | |
'Canonical mask', | |
'Stable', | |
'Displayable', | |
'Edges from' | |
] | |
const getLine = (key, node) => [ | |
key, | |
node['names']['en-GB'], | |
node['names']['cy'], | |
node['meta']['canonical'], | |
node['meta']['canonical-mask'], | |
node['meta']['stable-name'], | |
node['meta']['display-name'], | |
node['edges']['from'] | |
] | |
const lines = Object.keys(graph) | |
.map((key) => getLine(key, graph[key])) | |
.map((line) => line.join('\t')) | |
const tsvContent = [] | |
.concat([header.join('\t')]) | |
.concat(lines) | |
.join('\n') | |
fs.writeFileSync(PATH_TO_TSV, tsvContent, 'utf8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment