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

knowledge-graph-js

v1.4.0

Published

Yet another client for Google Knowledge Graph

Downloads

40

Readme

This library is a ES6 client to get internet knowledge information from various providers:

The library is tested out recurrently on a dataset using ava, superstruct and Travis CI.

Usage

In Google Cloud Platform, make sure to activate Knowledge Graph Search API and assign your API key to process.env.GOOGLE_API_KEY.

In Wolfram|Alpha developer portal, create an application and assign your AppID to process.env.WOLFRAM_APP_ID.

See the samples folder for more usecases.

Running with Node.js

const knowledge = require('knowledge-graph-js')

// Search using only a query
knowledge.search('katy perry')

// Search specifying the entity type
knowledge.search('Madison Square Garden', 'Place')

// List of available graph entities
knowledge.entities

Basic example

$ node samples/quickstart.js
knowledge.search('katy perry').then(res => {
  console.log(res.top)
})

/*
{ '@id': 'kg:/m/03y82t6',
  name: 'Katy Perry',
  '@type': [ 'Person', 'Thing' ],
  description: 'American singer-songwriter',
  image:

   { contentUrl: 'http://t3.gstatic.com/images?q=tbn:ANd9GcQrlKFmaiEtUImNiuD_pqzHPjDcjF4yaRThSFMh-rYuB8snFUfk',
     url: 'https://en.wikipedia.org/wiki/Katy_Perry' },
  detailedDescription:
   { articleBody: 'Katheryn Elizabeth Hudson, known professionally as Katy Perry, is an American singer and songwriter. After singing in church during her childhood, she pursued a career in
gospel music as a teenager. ',
     url: 'https://en.wikipedia.org/wiki/Katy_Perry',
     license: 'https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License' },
  url: 'http://www.katyperry.com/' }
*/

Benchmarking results

$ node samples/benchmark.js
const patriarchy = require('patriarchy')

knowledge.google.search('katy perry').then(res => {
  console.log(patriarchy(res.top))
})

knowledge.duckduckgo.search('katy perry').then(res => {
  console.log(patriarchy(res.top))
})

knowledge.wolfram.search('katy perry').then(res => {
  console.log(res)
})

Keywords extraction

$ node samples/keywords.js
const natural = require('natural')

knowledge.search('nelson mandela').then(res => {
  const {description, detailedDescription} = res.top
  console.log(res.top)
  console.log(description)

  natural.PorterStemmer.attach()
  console.log(description.tokenizeAndStem())
  console.log(detailedDescription.articleBody.tokenizeAndStem())
})

/*
{ '@id': 'kg:/m/05g7q',
  name: 'Nelson Mandela',
  '@type': [ 'Person', 'Thing' ],
  description: 'Former President of South Africa',
  image:
   { contentUrl: 'http://t1.gstatic.com/images?q=tbn:ANd9GcTFuD6oHFEztHdeTZTBHMQK-HHe1WKUeTzT0blYtptSvVlaOvRc',
     url: 'https://commons.wikimedia.org/wiki/File:Nelson-Mandela-with-congressman-Engel.png' },
  detailedDescription:
   { articleBody: 'Nelson Rolihlahla Mandela was a South African anti-apartheid revolutionary, political leader, and philanthropist, who served as President of South Africa from 1994 to 1999
. ',

     url: 'https://en.wikipedia.org/wiki/Nelson_Mandela',
     license: 'https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License' },
  url: 'http://www.nelsonmandela.org/' }

[ 'former', 'presid', 'south', 'africa' ]
[ 'nelson', 'rolihlahla', 'mandela', 'south', 'african', 'anti', 'apartheid', 'revolutionari', 'polit', 'leader', 'philanthropist', 'serv', 'presid', 'south', 'africa', '1994', '1999' ]
*/

Contributions

Changes and improvements are welcome! Feel free to fork and open a pull request into master.

You can lint the code and run all unit tests using npm test.

Roadmap

License

knowledge-graph-js is licensed under the Apache 2.0 License.

References