Coder Social home page Coder Social logo

krismuniz / google-kgsearch Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 2.0 6 KB

A simple wrapper for Google's Knowledge Graph Search API.

Home Page: https://www.npmjs.com/package/google-kgsearch

License: MIT License

JavaScript 100.00%
google knowledge-graph search npm

google-kgsearch's Introduction

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

google-kgsearch's People

Contributors

adrianca avatar krismuniz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

google-kgsearch's Issues

Entity specific info

I am currently using your Knowlegde Graph search API in system which is a nice feature.
However I am very interested in the possibility of having it return information such as phone number and address (specific info for entity type as Organisation).
There for Iwant to kindly request that you add that to the API.  

Err is null

Thanks for the package. However we found that during error cases (invalid ids for example), err is null.

        kGraph.search(kg_params, (err, items) => {
            console.log(err);
            if (err) {
                console.log("error");
                Sentry.captureException(err);
                console.error(err);
            };

I am wondering how could this problem be fixed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.