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

semanticfacets

v1.0.0

Published

A library for automatic facet generation over SPARQL-endpoints.

Downloads

3

Readme

Semantic Facets

A library for automatic facet generation over SPARQL-endpoints.

The provided code currently just supports the SPARQL endpoint of Wikidata. However, the library can be adapted to any knowledge graph.

Install

semanticFacets is available on npm.

npm install semanticfacets --save

Tests

To run the test first download the repository and install the dependencies. Then run npm test.

npm install
npm test

Note that some tests will connect to the Wikidata SPARQL endpoint.

Usage

import { getFacets, ThrottledRequest } from 'semanticfacets';

// get the request from somewhere
const iris = [ /* some Wikidata resource IRIs */ ];

// default endpoint is set to Wikidata
const connection = ThrottledRequest();

const facets = await getFacets( connection, iris, 5 );

// display facets
// ...

API

getFacets( connection, iris, facetCount )

Main entry point to retrieve the facets.

  • connection( query, options ) ... a callback to run SPARQL queries
    • query ... a string containing the query itself
    • returns a flattened object containing the query results
  • iris ... an array of resource IRIs given as string
  • facetCount ... the number of facets to retrieve
  • returns a Promise to an array of Facet-objects

ThrottledRequest( endpoint, maxRequests )

Factory to create a connection callback for getFacets().

  • endpoint ... a string containing the URL to a SPARQL endpoint; defaults to the Wikidata endpoint
  • maxRequests ... maximum number of parallel requests; defaults to 5
  • returns a connection callback function for getFacets()

Results

Facet

Wrapper for a single facet

Properties

  • datatype ... the datatype of this facet's facet values given as an IRI
  • path ... the property path for this facet; array of Property
  • values ... the facet values for this facet; array of Value

Property

Wrapper for RDF-properties

Properties

  • iri ... the IRI of this property
  • entity ... the associated entity's IRI for this property
  • label ... the label for this property

Value

Wrapper for facet values

Properties

  • iri ... the IRI representing this value or null for quantitative facets
  • label ... the label for this value
  • count ... the value size, i.e. number of input resources connected this value

Benchmarking

In the development we used a bunch of scripts helping us to understand the facet generation process and measure its performance. All scripts are included in the repository under /perf/ and can be run using npm run [name]. To configure the respective test, adapt the configuration object at the top of the respective script.

benchmark

Benchmarks the overall facet generation process.

countCandidates

Attempts to retrieve the number of candidates from the SPARQL endpoint for varying path lengths.

testSemanticSimilarity

Runs the semantic similarity for a selected subset of entities.

trackQueries

Measures the number of executions and their respective runtime for all SPARQL queries.