npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sparql-table-spec

v1.0.8

Published

takes a spec object for a table and outputs sparql string

Downloads

8

Readme

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: "http://xmlns.com/foaf/0.1/",
        ex: "http://example.info/vocab/"
    },
    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: <http://xmlns.com/foaf/0.1/>
PREFIX ex: <http://example.info/vocab/>
SELECT ?item ?name
WHERE {
 { 
     ?item rdf:type ex:PunkRocker .
	    
     ex:Johnny foaf:knows ?item .
	    
     OPTIONAL {
	    ?item foaf:name """Sheena""" .
	    
     } 
 }
 OPTIONAL {
	    ?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

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

Page

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

Path

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

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

views are the columns which should appear in the table

Sorts

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