Universal internet knowledge search client for Google, DuckDuckGo, Wolfram|Alpha
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 = // Search using only a queryknowledge // Search specifying the entity typeknowledge // List of available graph entitiesknowledgeentities
Basic example
$ node samples/quickstart.js
knowledge /*{ '@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 ingospel 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 = knowledgegoogle knowledgeduckduckgo knowledgewolfram
Keywords extraction
$ node samples/keywords.js
const natural = knowledge /*{ '@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
- Unit tests for errors (API responses, validation errors from superstruct) returning-errors, throwing-errors, custom-errors
- Make the
README
clearer and write more code samples
License
knowledge-graph-js
is licensed under the Apache 2.0 License.