Skip to content

Commit

Permalink
Merge pull request #78 from linkedconnections/development
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
julianrojas87 authored Jan 1, 2025
2 parents f619464 + e194687 commit cc411a1
Show file tree
Hide file tree
Showing 12 changed files with 1,020 additions and 561 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout
Expand Down
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

30 changes: 0 additions & 30 deletions jest.polyfills.js

This file was deleted.

8 changes: 3 additions & 5 deletions lib/Connections2CSV.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Transform } = require('stream');
import { Transform } from 'stream';

class Connections2CSV extends Transform {
export class Connections2CSV extends Transform {
constructor() {
super({ objectMode: true });
this._headerStreamed = false;
Expand All @@ -26,6 +26,4 @@ class Connections2CSV extends Transform {
set headerStreamed(value) {
this._headerStreamed = value;
}
}

module.exports = Connections2CSV;
}
18 changes: 8 additions & 10 deletions lib/Connections2JSONLD.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { Transform } = require('stream');
const uri_templates = require('uri-templates');
const Utils = require('./Utils');
import { Transform } from 'stream';
import utpl from 'uri-templates';
import Utils from './Utils';

class Connections2JSONLD extends Transform {
export class Connections2JSONLD extends Transform {
constructor(streamContext, templates) {
super({ objectMode: true });
this._streamContext = streamContext || false;
Expand Down Expand Up @@ -60,10 +60,10 @@ class Connections2JSONLD extends Transform {
}

// Predefined URI templates
const stopTemplate = uri_templates(this.templates['stop']);
const routeTemplate = uri_templates(this.templates['route']);
const tripTemplate = uri_templates(this.templates['trip']);
const connectionTemplate = uri_templates(this.templates['connection']);
const stopTemplate = utpl(this.templates['stop']);
const routeTemplate = utpl(this.templates['route']);
const tripTemplate = utpl(this.templates['trip']);
const connectionTemplate = utpl(this.templates['connection']);

// Resolve values for URIs
const departureStopURI = Utils.resolveURI(stopTemplate, conn, this.templates['resolve'], "departureStop");
Expand Down Expand Up @@ -111,5 +111,3 @@ class Connections2JSONLD extends Transform {
return this._templates;
}
}

module.exports = Connections2JSONLD;
130 changes: 64 additions & 66 deletions lib/Connections2Triples.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const { Transform } = require('stream');
const N3 = require('n3');
const { DataFactory } = N3;
const { namedNode, literal, quad } = DataFactory;
const uri_templates = require('uri-templates');
const Utils = require('./Utils');
import { Transform } from 'stream';
import utpl from 'uri-templates';
import Utils from './Utils';
import { DataFactory } from "rdf-data-factory";

class Connections2Triples extends Transform {
const df = new DataFactory();

export class Connections2Triples extends Transform {
constructor(templates) {
super({ objectMode: true });
this._templates = templates;
}

_transform(conn, encoding, done) {
// Predefined URI templates
const stopTemplate = uri_templates(this.templates['stop']);
const routeTemplate = uri_templates(this.templates['route']);
const tripTemplate = uri_templates(this.templates['trip']);
const connectionTemplate = uri_templates(this.templates['connection']);
const stopTemplate = utpl(this.templates['stop']);
const routeTemplate = utpl(this.templates['route']);
const tripTemplate = utpl(this.templates['trip']);
const connectionTemplate = utpl(this.templates['connection']);

// Resolve values for URIs
const departureStopURI = Utils.resolveURI(stopTemplate, conn, this.templates['resolve'], "departureStop");
Expand All @@ -30,74 +30,74 @@ class Connections2Triples extends Transform {

if (conn['type'] === 'Connection') {
this.push(
quad(
namedNode(connectionURI),
namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#Connection')));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#Connection')));
} else {
this.push(
quad(
namedNode(connectionURI),
namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#CancelledConnection')));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#CancelledConnection')));
}

this.push(
quad(
namedNode(connectionURI),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#departureStop'),
namedNode(departureStopURI)));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#departureStop'),
df.namedNode(departureStopURI)));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#arrivalStop'),
namedNode(arrivalStopURI)));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#arrivalStop'),
df.namedNode(arrivalStopURI)));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#departureTime'),
literal(conn['departureTime'].toISOString(), namedNode('http://www.w3.org/2001/XMLSchema#dateTime'))));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#departureTime'),
df.literal(conn['departureTime'].toISOString(), df.namedNode('http://www.w3.org/2001/XMLSchema#dateTime'))));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#arrivalTime'),
literal(conn['arrivalTime'].toISOString(), namedNode('http://www.w3.org/2001/XMLSchema#dateTime'))));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#arrivalTime'),
df.literal(conn['arrivalTime'].toISOString(), df.namedNode('http://www.w3.org/2001/XMLSchema#dateTime'))));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#departureDelay'),
literal(conn['departureDelay'], namedNode('http://www.w3.org/2001/XMLSchema#integer'))));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#departureDelay'),
df.literal(conn['departureDelay'], df.namedNode('http://www.w3.org/2001/XMLSchema#integer'))));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://semweb.mmlab.be/ns/linkedconnections#arrivalDelay'),
literal(conn['arrivalDelay'], namedNode('http://www.w3.org/2001/XMLSchema#integer'))));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://semweb.mmlab.be/ns/linkedconnections#arrivalDelay'),
df.literal(conn['arrivalDelay'], df.namedNode('http://www.w3.org/2001/XMLSchema#integer'))));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://vocab.gtfs.org/terms#headsign'),
literal(conn['headsign'], namedNode('http://www.w3.org/2001/XMLSchema#string'))));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://vocab.gtfs.org/terms#headsign'),
df.literal(conn['headsign'], df.namedNode('http://www.w3.org/2001/XMLSchema#string'))));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://vocab.gtfs.org/terms#trip'),
namedNode(tripURI)));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://vocab.gtfs.org/terms#trip'),
df.namedNode(tripURI)));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://vocab.gtfs.org/terms#route'),
namedNode(routeURI)));
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://vocab.gtfs.org/terms#route'),
df.namedNode(routeURI)));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://vocab.gtfs.org/terms#dropOffType'),
namedNode(dropOffType)
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://vocab.gtfs.org/terms#dropOffType'),
df.namedNode(dropOffType)
));
this.push(
quad(
namedNode(connectionURI),
namedNode('http://vocab.gtfs.org/terms#pickupType'),
namedNode(pickupType)
df.quad(
df.namedNode(connectionURI),
df.namedNode('http://vocab.gtfs.org/terms#pickupType'),
df.namedNode(pickupType)
));

done(null);
Expand All @@ -106,6 +106,4 @@ class Connections2Triples extends Transform {
get templates() {
return this._templates;
}
}

module.exports = Connections2Triples;
}
28 changes: 13 additions & 15 deletions lib/GtfsIndex.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { URL } = require('url');
const { request } = require('undici');
const util = require('util');
const fs = require('fs');
const csv = require('fast-csv');
const del = require('del');
const childProcess = require('child_process');
const { Level } = require('level');
const Utils = require('./Utils');
import { URL } from 'url';
import { request } from 'undici';
import util from 'util';
import fs from 'fs';
import { parse as parseCsv } from 'fast-csv';
import { deleteAsync as del } from 'del';
import childProcess from 'child_process';
import { Level } from 'level';
import Utils from './Utils';

const exec = util.promisify(childProcess.exec);

class GtfsIndex {
export class GtfsIndex {
constructor(options) {
this._path = options.path;
this._auxPath = options.auxPath || '.tmp';
Expand Down Expand Up @@ -171,7 +171,7 @@ class GtfsIndex {
async createIndex(path, map, key, tpr) {
if (fs.existsSync(path)) {
let stream = fs.createReadStream(path, { encoding: 'utf8', objectMode: true })
.pipe(csv.parse({ objectMode: true, headers: true }))
.pipe(parseCsv({ objectMode: true, headers: true }))
.on('error', err => { throw err; });

for await (const data of stream) {
Expand Down Expand Up @@ -212,7 +212,7 @@ class GtfsIndex {
let currentTrip = [];

let stream = fs.createReadStream(path, { encoding: 'utf8', objectMode: true })
.pipe(csv.parse({ objectMode: true, headers: true }))
.pipe(parseCsv({ objectMode: true, headers: true }))
.on('error', err => { throw err });

for await (const data of stream) {
Expand Down Expand Up @@ -248,7 +248,7 @@ class GtfsIndex {

async processCalendarDates(path, map) {
let stream = fs.createReadStream(path, { encoding: 'utf8', objectMode: true })
.pipe(csv.parse({ objectMode: true, headers: true }))
.pipe(parseCsv({ objectMode: true, headers: true }))
.on('error', err => { throw err });

for await (const data of stream) {
Expand Down Expand Up @@ -329,5 +329,3 @@ class GtfsIndex {
return this._headers;
}
}

module.exports = GtfsIndex;
Loading

0 comments on commit cc411a1

Please sign in to comment.