shex icon indicating copy to clipboard operation
shex copied to clipboard

reusable validator

Open ericprud opened this issue 8 years ago • 6 comments

It's common to create a validator with a schema and test many instances against it, e.g. an ingestion validator for a web service.

- interface ShExProcessor {
-     Promise validate((USVString or RDFGraph) schema,
-                      (USVString or RDFGraph) graph,
-                      ShapeMap shapeMap,
-                      optional ShExOptions? options);
- };
+ interface ShExProcessor {
+     Validator validate((USVString or RDFGraph) schema,
+                        optional ValidatorOptions? options);
+ };
+ interface Validator {
+     Promise validate((USVString or RDFGraph) graph,
+                      ShapeMap shapeMap,
+                      optional ValidationOptions? options);
+ };

ericprud avatar Apr 26 '17 07:04 ericprud

Two interfaces? Standard for WebIDL lately has been to use promises. If you did want to define a synchronous interface, perhaps simply use a different method? The method could be defined to simply invoke the promise. There's some discussion of that here, but I'm not sure why this is really necessary.

In any case, the Validator type would need to be defined, but should probably simply return ShapeResults.

gkellogg avatar Apr 26 '17 16:04 gkellogg

I don't think this is a synchronicity issue. I think it's just one of whether the API caters to the use case of reusing a schema for multiple validations. If the web API is any predictor for this, the shex.js interface is quite general, e.g. you can start it with some data and then throw successive schemas at it, or even start it with a schema and data and interrogate multiple ShapeMaps, but the common case is to start it with a schema and then query it iteratively with successive data and shapeMap reqs.

ericprud avatar Apr 28 '17 09:04 ericprud

Okay, I can see the value in this. Not sure that in WebIDL a call can return an interface, as it's not really object-oriented. Perhaps both methods are in the ShExProcessor interface, and a parse method returns an instance of a Validator type, which is then used as an argument to a validate method. The validate method could also be as it is now, but have schema be (USVString or RDFGraph or Validator); this is a short-cut for when the validator is not reused..

gkellogg avatar Apr 28 '17 14:04 gkellogg

I would define it more like

- interface ShExProcessor {
-     Promise validate((USVString or RDFGraph) schema,
-                      (USVString or RDFGraph) graph,
-                      ShapeMap shapeMap,
-                      optional ShExOptions? options);
- };
+ #sync version
+ interface ShExProcessor {
+    ShExSchema parseSchema(USVString schema) raises(ShExError);
+    Graph parseGraph(USVString or RDFGraph) raises(ShExError);
+    USVString validate(ShExSchema schema,
+                      Graph graph,
+                      USVString shapeMap,
+                      optional ShExOptions? options);
+ };
+ interface ShExSchema {
+ };
+ interface Graph {
+ };
+ #async version
+ interface ShExProcessor {
+    Promise<ShExSchema> parseSchema(USVString schema);
+    Promise<Graph> parseGraph(USVString or RDFGraph);
+    #Input parameters are also promises so that both schema can be parsed in parallel
+    Promise<USVString> validateAsync(Promise<ShExSchema> schema,
+                      Promise<Graph> graph,
+                      USVString shapeMap,
+                      optional ShExOptions? options);
+ };

I do not have a separate Validator class as this would break the async construct with the Promises. If the shapeMap would be also a promise object, it would be in theory possible to have all 4 elements running in parallel (would not be practical doh I think).

jessevdam avatar May 11 '17 19:05 jessevdam

I wrote this up without Promises in asyncAPI.

ericprud avatar May 12 '17 00:05 ericprud

Looks like it's a synchronous, rather than asynchronous API.

gkellogg avatar May 12 '17 01:05 gkellogg