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

vocabulary-recommender

v2.0.2

Published

A generic linked data vocabulary recommender library that provides recommendation functions for various backends.

Downloads

12

Readme

Vocabulary Recommender Command-line interface (CLI)

The vocabulary recommender CLI provides a recommendation interface which returns relevant Internationalized Resource Identifiers (IRIs) based on the search input. It works with SPARQL or Elasticsearch endpoints which contain relevant vocabulary datasets.

Homogeneous recommendations

The vocabulary recommender supports multiple search terms. The algorighm minimizes the number of vocabularies required for a set of recommendations. For example, the result sdo:Person sdo:knows would be preferred above sdo:Person foaf:knows, because the former only requires one vocabulary, whereas the latter requires two. A comprehensive literature study has been conducted to find a suitable algorithm, which resulted in using combiSQORE.

Installation

A. When pulling this repository from GitHub:

  1. Run yarn to install the dependencies.
  2. Run yarn build to generate the JavaScript code.
  3. Run yarn recommend to run the JavaScript code.

Run yarn recommend --help to see which arguments can be specified.

An example query looks as follows: yarn recommend -t person -c class

 

New to yarn? The instructions to download and install yarn can be found (here).

 

B. When installing the npm package "vocabulary-recommender":

The npm package can be installed with: yarn add vocabulary-recommender or npm i vocabulary-recommender

The command vocabulary-recommender <input arguments> only works from any directory in terminal when this package is installed globally!

NOTE: For safety reasons, it is NOT recommended to install npm packages globally! But if you wish to have easier access and have a true CLI experience, this can be done with the command: yarn global add vocabulary-recommender Otherwise, just change directory (cd) to the location where the package was installed.

 

Configuration

Configuration file

The configuration file conf.json is created during the first run of the vocabulary recommender and saved in the project directory. It has the following format:

{
  defaultEndpoint: "defaultkey",
  defaultQueryClass: "defaultQueryClass.rq",
  defaultQueryProperty: "defaultQueryProperty.rq",
  defaultQueryESClass: "./queries/defaultESClass.json",
  defaultQueryESProperty: "./queries/defaultESProp.json",
  endpoints: {
    "defaultkey": {
      type: "search",
      url: "https://api.endpoint.nl/",
    },
    "otherkey": {
      type: "sparql",
      url: "https://api.endpoint.nl/sparql",
      queryClass: "configuredQueryClass.rq",
      queryProperty: "configuredQueryProperty.rq",
    },
  },
} 

Endpoint Configuration: In the configuration file, endpoints can be specified by providing the endpoints key name, together with the key url and the key type of the endpoint. A default endpoint can be set using the key name of the endpoint.

To specify the endpoint(s) that is/are used, add the -e flag and the endpoint name to the input command:

yarn recommend -t person -c class -e otherkey

When no endpoint is specified, the default endpoint is used automatically. When the number of endpoints is less than the number of search terms, the default endpoint is used for the rest of the search terms.

yarn recommend -t person -c class -> defaultkey is queried. yarn recommend -t person knows -c class property -e otherkey -> otherkey is queried for the search term 'person'. defaultkey is used for the search term 'knows'.

Query Configuration: Four default queries must be specified: defaultQueryClass, defaultQueryProperty, defaultQueryESClass and defaultQueryESProperty. It is also possible to specify specific configured queries under the queryClass and queryProperty keys. The query corresponding to the set category (class / property) is selected automatically according to the configuration. The SPARQL queries should be stored in a file with the extension .rq and should contain the searchterm ${term} in the following format:

select ?iri ?desc ?score where {
  filter(regex(str(?iri),'${term}','i'))
  ?iri dct:description ?desc .
}

SPARQL queries must always return the variables iri and score. Elasticsearch queries must always return the _id and the _score which are retrieved by using bool queries. They should be stored in a .json file.

The results always return the same information that the query returns. That means that our previous example would not only return the iri and the score but also the description.

Preferred vocabularies configuration

You also configure a preference ordering of vocabularies by passing a dictionary with your preferred vocabularies as a parameter when calling the homogeneousRecommendation() function. The key is the prefix of the vocabulary, and the value represents the importance of the vocabulary. Internally, the preference ordering works by exploiting the fact that the ordering of vocabularies influences the result of the combiSQORE algorithm that has been chosen for the vocabulary recommender.

{
  "prefix1": 10,
  "prefix2": 15
}

Output as JSON

Because of the use of yarn, using yarn recommend <searchTerm> <category> <endpoint> -f json > example.json will create a json file that does not have the correct syntax due to the added yarn information.

To avoid this behaviour, run the script directly with node: node --no-warnings ./dist/recommend <searchTerm> <category> <endpoint> -f json > example.json