[go: up one dir, main page]

Skip to content

An ES6 client for Google, DuckDuckGo, Wolfram knowledge services

License

Notifications You must be signed in to change notification settings

mycaule/knowledge-graph-js

Repository files navigation

Knowledge graph

Universal internet knowledge search client for Google, DuckDuckGo, Wolfram|Alpha

Build Status dependencies Status devDependencies Status
npm package npm package npm package

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

About

An ES6 client for Google, DuckDuckGo, Wolfram knowledge services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published