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

gavagai

v0.2.2

Published

A Gavagai API helper library

Downloads

4

Readme

gavagai-node

Node.js helper library for Gavagai API

Install

$ npm install gavagai

Api key

Get your own api key for free at Gavagai Developer Portal.

Use

See Gavagai API documentation for details about available API resources.

Lexicon

Lookup a word in Gavagai living lexicon.

var gavagai = require('gavagai');
var client = gavagai('GAVAGAI_APIKEY');

// getting all info about 'good'
client.lexicon('good', function (err, data) {
    console.log('lexicon returned:', data);
});

Stories

Given a set of texts, return summaries as a set of stories.

var gavagai = require('gavagai');
var client = gavagai('GAVAGAI_APIKEY');

var texts = [
    'Stayed here for 3 nights at the beginning of a trip of California. Could not say enough good things about the hotel Monaco. Amazing staff, amazing rooms and the location is brilliant! First stay at a Kimpton hotel, but definitely not the last!!!',
    'I did a lot of research looking for a hotel suite for our family vacation in San Francisco. The Hotel Monaco was a perfect choice. What friendly and delightful staff. I will miss the Grand Cafe, but I will make sure to come back to see their new offerings.',
    'My partner and I spent four nights here over New Years and loved it. Super staff; lovely, quiet room; excellent location within easy walking to much of Downtown and an overall experience that was perfect.'
];

client.stories(texts, function(err, data) {
    if (err) {
        console.error('error:', err);
    }
    console.log('stories returned:', data);
});

Topics

Given a set of texts, return significant topics and keywords.

client.topics(texts, function(err, data) {
    if (err) {
       console.error('error:', err);
    }
    console.log('stories returned:', data);
});

Keywords

Extract salient concepts from a collection of texts. Order by number of occurrences.

client.keywords(texts, function(err, data) {
    if (err) {
       console.error('error:', err);
    }
    console.log('keywords returned:', data);
});

Tonality

For each text, return their tonality based on lexical analysis in multiple dimensions. This method accepts either a single string, or an array of texts as input.

client.tonality("it’s beautiful and makes me want to cry", function(err, data) {
    if (err) {
       console.error('error:', err);
    }
    console.log('stories returned:', data);
});

Options

All methods accepts options as a second paramter. Options are corresponding to API parameters. E.g. if I have a set of french texts that I want to analyze:

client.topics(texts, { language: 'fr' }, function(err, data) {
    if (err) {
       console.error('error:', err);
    }
    console.log('stories returned:', data);
});

Document IDs

In some situations documents have a specific identifiers. In that case, you can use an array of objects that have properties id and body.

var texts = [
    {
      id: '1',
      body: 'Stayed here for 3 nights at the beginning of a trip of California. Could not say enough good things about the hotel Monaco. Amazing staff, amazing rooms and the location is brilliant! First stay at a Kimpton hotel, but definitely not the last!!!',
    },
    {
      id: '2',
      body: 'I did a lot of research looking for a hotel suite for our family vacation in San Francisco. The Hotel Monaco was a perfect choice. What friendly and delightful staff. I will miss the Grand Cafe, but I will make sure to come back to see their new offerings.',
    },
    {
      id: '3',
      body: 'My partner and I spent four nights here over New Years and loved it. Super staff; lovely, quiet room; excellent location within easy walking to much of Downtown and an overall experience that was perfect.'
    }
];

Promises

One method for for handling the common problem with deeply nested callbacks, is to use promises. Gavagai-node uses the Q library to provide an alternative to callbacks.

See example in promises.js for how to make an api call with promises.

Running tests

Start by install grunt-cli:

$ npm install -g grunt-cli

Execute specs:

$ grunt

Execute smoke tests against live API:.

$ grunt smoke