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] How to use the DataFactory provided by N3 #143

Closed
MMesch opened this issue Aug 22, 2024 · 2 comments
Closed

[Question] How to use the DataFactory provided by N3 #143

MMesch opened this issue Aug 22, 2024 · 2 comments

Comments

@MMesch
Copy link

MMesch commented Aug 22, 2024

Is it possible to use the DataFactory object from the N3 library?

When I naively try new SHACLValidator(shapes, { factory: DataFactory }); I get:

Type 'typeof DataFactory' is not assignable to type 'Factory<Quad, Quad, DatasetCore<Quad, Quad>>'.
  Property 'dataset' is missing in type 'typeof DataFactory' but required in type 'DatasetCoreFactory<Quad, Quad, DatasetCore<Quad, Quad>>'. (tsserver 2322)

It did work well for me with rdf-ext but I wanted to avoid converting quad objects back and forth and also the extra dependency if possible.

I am not super experienced with Typescript. Any idea how to fix or work around this?

@MMesch
Copy link
Author

MMesch commented Aug 23, 2024

Fixed using this new factory instead:

export const ExtendedDataFactory = {
	...DataFactory,
	dataset: quadsToN3Store
}

export function quadsToN3Store(quads: Quad[]): Store {
	return new Store(quads);
}

N3 also has a DataSetCoreFactory since recently (see rdfjs/N3.js#314 and https://github.com/rdfjs/N3.js/pull/398/files) but I struggled to use it since it's implemented as a class static function and I (beginner in Typescript, sorry) don't know how to efficiently combine that class with the DatasetFactory required by the SHACLValidator constructor.

@MMesch MMesch closed this as completed Aug 23, 2024
@tpluscode
Copy link
Collaborator

Hello @MMesch. I'm glad you found a workaround.

Turns out that N3 types published from Definitely Types do not yet export the store. (PR DefinitelyTyped/DefinitelyTyped#70364)

In the future, I would like to be able to use N3 factories with RDF/JS Environment like,

import SHACLValidator from 'rdf-validate-shacl'
import { DataFactory, StoreFactory } from 'n3'
import Environment from '@rdfjs/environment'

const factory = new Environment([DataFactory, StoreFactory])

const validator = new SHACLValidator(shapes, { factory })

That, however, will require some changes in n3

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