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

google-kgsearch

v0.1.1

Published

A simple wrapper for Google's Knowledge Graph Search API

Downloads

144

Readme

google-kgsearch

Code-Style:Standard License:MIT

google-kgsearch is a wrapper for Google's Knowledge Graph Search API. It is lightweight, simple, and easy to understand.

About Google's Knowledge Graph Search API:

The Knowledge Graph Search API lets you find entities in the Google Knowledge Graph. The API uses standard schema.org types and is compliant with the JSON-LD specification.

An excerpt from: https://developers.google.com/knowledge-graph/

Use cases

Some examples of how you can use the Knowledge Graph Search API include:

  • Getting relevant information about a specific entity when doing Natural Language Processing
  • Getting a ranked list of the most notable entities that match certain criteria.
  • Predictively completing entities in a search box.
  • Annotating/organizing content using the Knowledge Graph entities.

Quick Example: Search for a Person

Create a KGSearch instance with your API Key, store it in a variable (in this case: kGraph), and then call kGraph.search(params, callback)

import KGSearch from 'google-kgsearch'
const kGraph = KGSearch(process.env.KGSEARCH_API_KEY)

let params = {
  query: 'Taylor Swift',
  types: 'Person',
  limit: 1
}

kGraph.search(params, (err, items) => {
  if (err) console.error(err)
  console.log(items)
})

Outputs an object:

[
  {
    '@type': 'EntitySearchResult',
    result: {
      '@id': 'kg:/m/0dl567',
      name: 'Taylor Swift',
      '@type': [object],
      description: 'Singer-songwriter',
      image: [object],
      detailedDescription: [object],
      url: 'http://www.taylorswift.com/'
    },
    resultScore: 280.279816
  }
]

See the example for more information.

Installation

Installing google-kgsearch is as simple as installing any other npm module:

$ npm install google-kgsearch --save

Requirements

To use this API you need an API key. An API key identifies your project to check quotas and access. Go to the Credentials page to get an API key.

Check out Google Developers' guide for more information.

Usage

Initialization

After importing the google-kgsearch file, you need to initialize a new KGSearch instance with your API_TOKEN and store it in a variable (in this case its kGraph):

import KGSearch from 'google-kgsearch'
const kGraph = KGSearch(process.env.KGSEARCH_API_KEY)

Search Google's Knowledge Graph

Use the .search() method to search Google's Knowledge Graph.

/* ... */

kGraph.search({ query: 'Puerto Rico'}, (err, items) => {
  if (err) console.error(err)
  console.log(items)
})

The kGraph.search(params, callback) method takes params as a first argument. Under the hood the module converts these into query strings.

It also takes a callback function to handle the data received from the API.

reference

KGSearch

| Argument | Type | Description |--- |--- |--- | api_key (required) | string | Enables access to the Google's Knowledge Graph Search API

.search()

Method of KGSearch(api_key)

| Argument | Type | Description |--- |--- |--- | params (required) | object | API query parameters (query, types, limit, etc.) | callback (required) | function | A function that handles the response data from the API

callback takes two arguments:

  1. err (for error handling; null if there are no errors)
  2. data (the data returned by the API)

Contributing

Bug Reports & Feature Requests

Something does not work as expected or perhaps you think this module needs a feature? Please open an issue using GitHub's issue tracker. Please be as specific and straightforward as possible.

Developing

Pull Requests (PRs) are welcome. Make sure you follow the same basic stylistic conventions as the original code (i.e. "JavaScript standard code style")

License

The MIT License (MIT)

Copyright (c) 2016 Kristian Muñiz