zazuko / rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
MIT License
98 stars 13 forks source link

API #15

Closed martinmaillard closed 4 years ago

martinmaillard commented 4 years ago

There are still some things in the API that I would like to change, but I would like your opinion before doing it @bergos.

1. The API is very imperative & stateful and I don't see a good reason for it (heritage from Java?)

Currently, the flow looks like:

const validator = SHACLValidator({ factory })
validator.getConfiguration().setSomething(...)
const report = validator.validate(data, shapes)

And the validator also exposes methods like loadDataGraph, loadShapesGraph, showValidationResults, etc...

I would prefer something like:

const validator = SHACLValidator({ factory, ...allTheOptions })
const report = validator.validate(data, shapes)

And to be honest, my favourite version would be:

const validationReport = SHACLValidator.validate(data, shapes, { factory, ...allTheOptions })

I don't see a reason why the validator needs to be an object holding state. Reusing the same validator object to validate multiple datasets doesn't seem useful to me. But maybe I'm missing something?

2. Some functions should be properties, mostly on ValidationReport

bergos commented 4 years ago

Yes, let's do it more the JS way.

1.

I think it should be possible to create instances to pass the options just once and pass the object around. Maybe we can add a static instance later, but I would like to gain experience first, before we add it as a feature.

Have you thought about adding an API like this?:

const shape = new SHACLShape(shapesDataset)
const report = shape.validate(dataset)

2.

👍

martinmaillard commented 4 years ago

I like your idea! It totally makes sense to prepare a validator based on a set of shapes and to use it to validate multiple datasets.

I would keep the SHACLValidator name instead of SHACLShape if you don't mind.

martinmaillard commented 4 years ago

Done