eddieantonio / node-sparql-client

A SPARQL client for Node.js
Other
19 stars 12 forks source link

Use prefix.cc to guess common namespaces #5

Open valentin0h opened 8 years ago

valentin0h commented 8 years ago

Would it be possible to enhance the list of COMMON_PREFIXES with a dynamic lookup on prefix.cc?

Might do it myself if you see it fit for your lib.

eddieantonio commented 8 years ago

Woah! I didn't know http://prefix.cc even existed! Pretty nifty, but I'm not sure it fits in this library. Especially since a dynamic look-up would probably require an asynchronous HTTP request before resolving any prefixes. Instead, I think a separate Node library may be a better idea: like a library that you can just use as follows:

import prefix from "prefix-cc";

prefix('rdf', 'foaf', 'owl').then(prefixes => {
   sparqlClient.register(prefixes);
});

A standalone command-line client may be useful as well.

eddieantonio commented 8 years ago

There is also this package: https://github.com/nak2k/node-rdf-prefixes/blob/master/index.js

CarlQLange commented 8 years ago

Oh man, that interface you laid out is super nice. Filing under great ideas

import prefix from "prefix-cc";

prefix('rdf', 'foaf', 'owl').then(prefixes => {
   sparqlClient.register(prefixes);
});
valentin0h commented 8 years ago

..and this http://prefix.cc/context

eddieantonio commented 8 years ago

I had a little time and whipped up prefix-cc. It works exactly more-or-less as I had proposed, plus has a simple command line client!

Try it! npm install prefix-cc --save

var prefix = require('prefix-cc');
var SparqlClient = require('sparql-client-2');

var client = new SparqlClient('http://dbpedia.org/sparql');

prefix('dbr', 'dbo')
  .then(prefixes => {
    client.register(prefixes);
    return Promise.resolve();
  })
  .then(() => {
    var query = client.query(`
      SELECT ?game
      WHERE {
        ?game dbo:series dbr:Metroid
      }`)
    return query.execute();
  })
  .then(response => {
    console.log(response.results.bindings);
  })
  .catch(err => {
    console.error(err);
    process.exit(-1);
  });

Edit: I realize that register() may need to return a resolved promise to make this melding of APIs prettier... and that that makes no sense since register() MUST return the client anyway...