PieceMeta / node-sparql-hollandaise

A JS client lib to communicate with a triple store database through SPARQL queries over HTTP.
MIT License
3 stars 3 forks source link

Support for triple pattern abbreviations in WHERE clause #1

Open martinleopold opened 8 years ago

martinleopold commented 8 years ago

The predicate-object list (http://www.w3.org/TR/rdf-sparql-query/#predObjLists)

 ?x  foaf:name  ?name ;
        foaf:mbox  ?mbox .

might be written as

  .where('?x', ['foaf:name  ?name', 'foaf:mbox  ?mbox'])

The object list (http://www.w3.org/TR/rdf-sparql-query/#objLists)

?x foaf:nick  "Alice" , "Alice_" .

might be written as

  .where('?x foaf:nick', ['"Alice"', '"Alice_"'])

So basically the syntax for the two cases is the same:

  .where(string, array)

To separate the two cases one might test the first argument (the string) for whitespace.

dasantonym commented 8 years ago

this is now implemented in a basic way as:

.where(new SPH.Triple('?x', ['foaf:name  ?name', 'foaf:mbox  ?mbox']));

and

.where(new SPH.Triple('?x foaf:nick', ['"Alice"', '"Alice_"']));

still need to think about the whole string parsing. for now i am inclined to only use the classes in the constructors:

var pattern = new SPH.GraphPattern([
    new SPH.Triple('?x foo:bar ?name'),
    new SPH.Triple('?x foaf:nick', ['"Alice"', '"Alice_"']),
    new SPH.Filter('... some filter clause ...')
]);
query.where(pattern);

the whole string-parsing alternative stuff is nice, but i think an oo-structure that provides basic validation and then converts into a sparql query string is more important. a proper string parser could follow and then be used in the class constructor methods.