Closed happybeing closed 4 years ago
Thanks -- I've updated the documentation and added an example, but concede this still needs more. Hopefully this helps for now?
I have several local projects using graphy at the moment but unfortunately they are under wraps pending publication(s).
P.S. If you have any specific use cases, I can surely help by adding some examples to the documentation. Otherwise, I am always available to respond in GH issues or on gitter 👍
Thanks @blake-regalia. I managed to make a DatasetTree
by first looking around in the source and I was add a couple of quads to it! I then iterated over these with for.. tree as quad
.
I wasn't able to use the Svelte {#each}
construct for iteration though, so I wonder if that relies on support for some other kind of iterator, or it might only work on arrays. I'll check this out with the Svelte community.
A new question, looking at your doc link it says:
returns a new
Duplex<Quad, Quad>
(acceptsQuad
objects on its writable side, pushesQuad
objects on its readable side)
Is there a discrepancy there, maybe just terminology, between DatasetTree
which I see in the debugger and Duplex<Quad, Quad>
? I am not very familiar with a lot of this so maybe misunderstand something basic! Thanks for your continuing offer to help.
Re Svelte {#each}
, any chance you can add a length
property to support this:
You can use each blocks to iterate over any array or array-like value — that is, any object with a length property.
Ref: https://svelte.dev/docs#each
This would make it possible to exploit one of the nice features of Svelte - compiling to reactive HTML/JS without using the DOM API.
Just a thought 😄 I guess I could create a wrapper object.
As for the Svelte {#each}
, the practice for iterators is to use: {#each [...iterable]}
-- which to me is an anti-pattern. I left a comment on the closed issue in the Svelte repo about supporting iterators but alas.
So for Dataset (which is iterable), you could do:
{#each [...dataset] as quad}
The Duplex signature is in reference to the node.js docs, which simply means that it extends both readable and writable interfaces. When webpack bundles this up, it uses some polyfills for the browser -- i think they are both whatwg compatible at this point.
@blake-regalia Another documentation example request. I'm trying to pass a stream
to contnt.ttl.read
using fetch()
but it is being rejected with error:
TypeError: unexpected input type: [object ReadableStream] at ./node_modules/@graphy/content.ttl.read/main.js.module.exports
Code:
let streamRdf;
fetch('http://www.w3.org/2000/01/rdf-schema')
.then(res => res.body)
.then(body => {
body.pipeTo(readTtl({
data(y_quad) {
console.log(JSON.stringify(y_quad));
$rdfDataset.add(y_quad);
console.log('rdfDataset size: ', $rdfDataset.size);
$rdfDataset = $rdfDataset;
},
eof(h_prefixes) {
console.log('done!');
console.log('rdfDataset size: ', $rdfDataset.size);
},
}))
})
.catch(err => console.error(err));
@theWebalyst this looks like a bug in graphy to me -- I believe the code here should work as expected. I will clone your svelte repo and investigate further.
It turns out graphy is not compatible with WHATWG stream pipe methods at the moment and so pipeTo
and pipeThrough
will not work with the readers, writers, or dataset -- my apologies. I will put this on the issue tracker.
In the meantime, you can revert to the legacy read/write style when using fetch:
fetch('http://www.w3.org/2000/01/rdf-schema')
.then(res => res.body)
.then((body) => {
let body_reader = body.getReader();
let ttl_reader = readTtl({
data(y_quad) {
console.log(JSON.stringify(y_quad));
// triples.push(y_quad);
// triples = triples;
},
eof(h_prefixes) {
console.log('done!');
},
});
function next() {
body_reader.read().then(read_chunk);
}
function read_chunk({value, done}) {
if(done) {
ttl_reader.end();
return;
}
ttl_reader.write(value);
next();
}
next();
});
P.S. @theWebalyst thanks for putting the svelte repo together, I've already learned something about stores after cloning it!
The destination is missing for https://graphy.link/memory.dataset.fast#construction
P.S. @blake-regalia do you have any example apps using graphy?