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

Creating JSON-LD from db.search() results #59

Open
BigBlueHat opened this issue Mar 14, 2017 · 2 comments
Open

Creating JSON-LD from db.search() results #59

BigBlueHat opened this issue Mar 14, 2017 · 2 comments

Comments

@BigBlueHat
Copy link
Member

Essentially, it'd be nice to do something like this:
https://github.com/mcollina/levelgraph-n3#exporting-ntriples-from-levelgraph

But I'm finding it tricky to accomplish using "raw" jsonld.js stuff coupled with the output of search.

However, even if it's possible via db.search() + jsonld.* (something), it'd be super to have this streamlined in some way, so that's more intuitive.

@BigBlueHat
Copy link
Member Author

What I'm doing now (fwiw) is using db.search (or db.nav) to get the subjects I want and then using db.jsonld.get to create the JSON-LD output.

It's working well enough atm, but I'm not sure how (yet) to best turn that into a db.jsonld.search() method. Ideas welcome! 💡

@BigBlueHat
Copy link
Member Author

Just hacked this together in a local copy of the playground + term() from https://github.com/warpr/turtle-to-jsonld/blob/master/lib/turtle-to-jsonld.js#L20-L45 for expanding the SPO to match what jsonld.js uses internally:

db.search([{subject: db.v('s'), predicate: db.v('p'), object: db.v('o')}], {}, (err, rv) => {
  var graphs = [];
  rv.forEach((spo) => {
    graphs.push({subject: term(spo.s), predicate: term(spo.p), object: term(spo.o)});
  });
  jsonld.fromRDF({'@default': graphs}, console.log);
});

The results seem accurate...so I'll try and hack this in + tests. However, before I dig too deeply, I'd appreciate any input on API preferences.

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

1 participant