Skip to content

Instantly share code, notes, and snippets.

@tvararu
Created May 22, 2017 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvararu/0d5db12d2913647e9b4da07b7b330b51 to your computer and use it in GitHub Desktop.
Save tvararu/0d5db12d2913647e9b4da07b7b330b51 to your computer and use it in GitHub Desktop.
// 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