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

Can't use local object to be validated #60

Open
matthieu-fesselier opened this issue Jun 13, 2019 · 3 comments
Open

Can't use local object to be validated #60

matthieu-fesselier opened this issue Jun 13, 2019 · 3 comments

Comments

@matthieu-fesselier
Copy link

I didn't manage to use a local object to be validated. This works:

ShEx.Loader.load([validationShape], [], [], [dataURL]).then(function (loaded) {
  var db = ShEx.Util.makeN3DB(loaded.data);
  var validator = ShEx.Validator.construct(loaded.schema, { results: "api" });
  var result = validator.validate(db, [{node: dataID, shape: shapeURL}]);
  return result;
}).catch(e => console.error(e));

But this throw an error:

ShEx.Loader.load([validationShape], [], [], [dataObject]).then(function (loaded) {
  var db = ShEx.Util.makeN3DB(loaded.data);
  var validator = ShEx.Validator.construct(loaded.schema, { results: "api" });
  var result = validator.validate(db, [{node: dataID, shape: shapeURL}]);
  return result;
}).catch(e => console.error(e));

Throw TypeError: Cannot use 'in' operator to search for 'productions' in undefined

Here is dataObject:

{
  title: "Title test",
  text: "Text test", 
  @id: "http://127.0.0.1:8000/conversations/7/"
}

Am I doing something wrong?

@matthieu-fesselier matthieu-fesselier changed the title Can't use local json object to validate Can't use local object to be validated Jun 13, 2019
@ericprud
Copy link
Contributor

ShEx.Loader.load is a convenience function to load schema and data remotely. If you've already got the data loaded, you should be able to just

let theGraph = someTriplifier(dataObject); # turn the dataObject into triples
ShEx.Loader.load([validationShape], [], [], []).then(function (loaded) {
  var db = ShEx.Util.makeN3DB(theGraph);
  var validator = ShEx.Validator.construct(loaded.schema, { results: "api" });
  var result = validator.validate(db, [{node: dataID, shape: shapeURL}]);
  return result;
}).catch(e => console.error(e));

If course the magic is in that someTriplifier() function I invented. If dataObject is JSON-LD, you should be able to create an @context and use toRDF() from the jsonld npm package.

@matthieu-fesselier
Copy link
Author

Thanks for the informations and sorry for the late reply.
The jsonld.toRDF() returns a string, but in the makeN3DB()function, you are using a N3Store, is that right?
How can I create this store? When I try to use N3, I have this error during the validation:

TypeError: db.getTriplesByIRI is not a function

Is it a N3 version problem?

@ericprud
Copy link
Contributor

I obviously dropped the ball on this issue, but A. yeah, it looked like a version issue and B. shex.js now uses a 1.0.x N3.js

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