Created
November 7, 2023 13:31
-
-
Save argahsuknesib/3ebdf5dc773e53a8a80394e931024c5e to your computer and use it in GitHub Desktop.
Reading from a pod with LDES in LDP.
This file contains hidden or 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
// download these packages from npm | |
// you can use the my template for an intial Typescript project: | |
// https://github.com/argahsuknesib/ts-template | |
import { LDESinLDP, LDPCommunication } from "@treecg/versionawareldesinldp"; | |
const N3 = require('n3'); | |
async function main() { | |
// let ldes_location = 'https://n061-14a.wall2.ilabt.iminds.be/dataset_participant1/data/'; //change this to the location of your LDES | |
let ldes_location = 'http://localhost:3000/dataset_participant1/data/'; | |
let communication = new LDPCommunication(); // this is an unauthenticated communication with the solid pod | |
let ldes_in_ldp = new LDESinLDP(ldes_location, communication); // the LDES in LDP class | |
// we read the sensor events as a stream | |
let from = '2021-05-01T00:00:00.000Z'; // the start date of the stream (change as your need) | |
let to = '2024-05-01T00:00:00.000Z'; // the end date of the stream (change as your need) | |
let stream = await ldes_in_ldp.readMembersSorted({ | |
from: new Date(from), | |
until: new Date(to), | |
chronological: true | |
}) | |
// now you read from the strem object | |
stream.on('data', (data) => { | |
let stream_store = new N3.Store(data.quads); | |
// console.log(stream_store); // this will be the sensor event printed as a Quad Store | |
for (let quad of stream_store.getQuads(null, null, null, null)) { | |
console.log(quad); // this will print the quads one by one | |
} | |
}) | |
stream.on('end', () => { | |
console.log('done reading from the stream'); | |
}) | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment