node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

gtfs-csv2rdf

gtfs-csv2rdf

Mapping library which transforms GTFS CSV files into GTFS triples using the GTFS vocabulary.

Use

Requirements:

  • node js

Install using npm install gtfs-csv2rdf --save

Command Line

In this case, you can install it globally using npm install -g gtfs-csv2rdf

# First argument: path to gtfs
# Second argument: the base URI
# Third argument (optional): the requested format (turtle (default), ntriples or jsonld)
gtfs-csv2rdf path-to-gtfs.zip http://data.gtfs.org/sample-feed/0.1/ turtle > gtfsintriples.ttl

As a nodejs library

By example:

var fs = require('fs');
var N3 = require('n3');
var gtfs-csv2rdf = require('gtfs-csv2rdf').zipToTriples;
var path = "/path/to/gtfs.zip";
if (/(.*\/)?(.*?)\.zip/.exec(path)) {
  var feedname = /(.*\/)?(.*?)\.zip/.exec(path)[2];
} else {
  throw "Not a zip file: " + path;
}
//create the writer of turtle file towards stdout 
var streamWriter = new N3.StreamWriter({ 'gtfs': 'http://vocab.gtfs.org/terms#',
                                         'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
                                         'foaf' : 'http://xmlns.com/foaf/0.1/',
                                         'dct' : 'http://purl.org/dc/terms/',
                                         'rdfs' : 'http://www.w3.org/2000/01/rdf-schema#',
                                         'owl' : 'http://www.w3.org/2002/07/owl#',
                                         'xsd' : 'http://www.w3.org/2001/XMLSchema#',
                                         'vann' : 'http://purl.org/vocab/vann/',
                                         'skos' : 'http://www.w3.org/2004/02/skos/core#',
                                         'dcat' : 'http://www.w3.org/ns/dcat#'});
streamWriter.pipe(process.stdout);
var options = {
  feedname : feedname,
  baseuri : "http://data.example.org/sample-feed/0.1/"
};
gtfscsv2rdf(fs.createReadStream(path), streamWriter, options);

For other functions, check out the main file of the library