Node Promiscuous Modules


    1.0.8 • Public • Published

    sparql-table-spec exports a function which translates a specification object to a SPARQL SELECT query. The specification object is intended as an intermediary form, between (say) a request to a REST API, and the generated SPARQL string; it should represent a useful subset of SPARQL expressivity, maintaining a higher level of abstraction than SPARQL, and a more readily manipulatable structure than a SPARQL AST.

    Example usage:

    const sparqlTable = require('./main.js')
    const output = sparqlTable({
        namespaces: {
            foaf: "",
            ex: ""
        filters: [ {
            literals: [
                { path: [{property: "foaf:name", optional: true}]
                , value: "Sheena" }
            uris: [
                { path: [{property: "rdf:type"}], value: "ex:PunkRocker"}
                , { path: [{property: "foaf:knows", inverse: true }], value: "ex:Johnny"}
        views: [
            { path: [{property: "foaf:knows", optional: true}, {property: "foaf:name"}], name: "name"}
        page: {number: 2, size: 50},
        sorts: [{ path: [{property: "foaf:knows", inverse: false }, {property: "foaf:name", optional: true}], order: "DESC"  }]

    Example output:

    PREFIX foaf: <>
    PREFIX ex: <>
    SELECT ?item ?name
    WHERE {
         ?item rdf:type ex:PunkRocker .
         ex:Johnny foaf:knows ?item .
         OPTIONAL {
            ?item foaf:name """Sheena""" .
            ?item foaf:knows ?foaf_knows .
            ?foaf_knows foaf:name ?name .
      ?item foaf:knows ?foaf_knows .
      OPTIONAL {
        ?foaf_knows foaf:name ?_sortValue0 .	    
    ORDER BY DESC(?_sortValue0)
    LIMIT 50
    OFFSET 49

    Structure of the Specification Object

    Spec:: {
      namespaces: {Prefix: URI},
      page: {number: PositiveInteger, size: PositiveInteger},
      filters: [{ (uri | literal | lang | datatype): [{path: Path, value: String}]}],
      views: [{path: Path, name: String}],
      sorts: [{path:Path, order: DESC | ASC}]
    Path:: [{property: String, optional: Boolean, inverse: Boolean}]


    Namespaces is a mapping of prefixes to URI namespaces. This allows you to use the abbreviated form of URIs, eg foaf:Person instead of (only abbreviated URIs are currently supported).


    This allows you to define how many results per page should be fetched (page.size), and which page of results to fetch (page.number)


    A Path is a non-empty array of objects of the form {property, optional, inverse}.

    • property is an abbreviated URI (eg: foaf:name) which translates to ?item foaf:name ?name .
    • optional is a Boolean (if absent, defaults to false) which wraps the rest of the path in OPTIONAL { }
    • inverse is a Boolean (if absent, defaults to false) which translates to ?knows foaf:knows ?item, where ?item is the resource being filtered.


    Filters allows you to define constraints on your result set. Given filters: [{ literals: [filterLA, filterLB]}] both must match. But given filters: [filterX, filterY], either filterX or filterY may match.


    views are the columns which should appear in the table


    sorts is the order by which results should be ordered. Each sort consists of a Path and a sort order.


    npm i sparql-table-spec

    DownloadsWeekly Downloads






    Unpacked Size

    12.4 kB

    Total Files


    Last publish


    • kwijibo