Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Extracting a DatasetCore<Quad, Quad> from Quadstore #171

Closed
MMesch opened this issue Jul 11, 2024 · 3 comments
Closed

Question: Extracting a DatasetCore<Quad, Quad> from Quadstore #171

MMesch opened this issue Jul 11, 2024 · 3 comments

Comments

@MMesch
Copy link

MMesch commented Jul 11, 2024

Thanks for writing this nice library.

I am quite new to the RDFJS world and trying to use Quadstore for a SHACL validation use case in combination with the rdf-validate-shacl library that expects Quads to be passed as a DatasetCore data type. From the documentation it seems to me Quadstore is not implementing that interface, although most functions seem to be there?

I currently tried something like

	async validateSHACL(shapes: DatasetCore) {
		const validator = new SHACLValidator(shapes, { factory: rdf });
		const allQuadsStream = await this.engine.queryQuads("CONSTRUCT WHERE {?s ?p ?o}");
		return await validator.validate(allQuadsStream);

This fails, as one would expect, with

Argument of type 'ResultStream<Quad>' is not assignable to parameter of type 'DatasetCore<Quad, Quad>'.

Any hints on how to best use these together?

@jacoscaz
Copy link
Owner

jacoscaz commented Jul 11, 2024

Hello @MMesch,

Thank you for your kind words! I am happy to admit I'm not as familiar with the Dataset RDF/JS interfaces but, insofar as I remember, the main difference is that the interfaces implemented by Quadstore (Source, Sink, Store) are asynchronous (event emitters, streams, promises) whilst Dataset interfaces are synchronous. As such there's no straightforward way for Quadstore to implement Dataset interfaces as the former is inherently asynchronous.

Bridging between the two therefore means getting quads out of Quadstore and into a DatasetCore instance in separate steps:

const { items: quads } = await store.get({});
let dataset = new DatasetCore();
for (quad of quads) {
  dataset = dataset.add(quad);
}

Or, if we use the Dataset interface:

const { items: quads } = await store.get({});
const dataset = new Dataset().addAll(quads);

(I'm not in a position to test these snippets right now. If you find yourself struggling let me know and I'll have a deeper look.)

@jacoscaz
Copy link
Owner

@MMesch feel free to reopen if you need any further help!

@MMesch
Copy link
Author

MMesch commented Jul 15, 2024

Thanks for your prompt reply. For now it's all good, I managed to solve it along the lines you described!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants