@klangoo/magnetapiclient

Magnet API client driver for NodeJS

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@klangoo/magnetapiclient
021.1.010 months ago6 years agoMinified + gzip package size for @klangoo/magnetapiclient in KB

Readme

This library allows you to easily use the Magnet API via NodeJS.
Table of Contents
About
Klangoo NLP API is a natural language processing (NLP) service that uses the rule-based paradigm and machine learning to recognize the aboutness of text. The service recognizes the category of the text, extracts key disambiguated topics, places, people, brands, events, and 41 other types of names; analyzes text using tokenization, parts of speech, parsing, word sense disambiguation, named entity recognition; and automatically finds the relatedness score between documents. Read More. Signup for a free trail
Installation

Prerequisites

Install

To use MagnetApiClient in your NodeJS project, you can either download the Magnet API Library directly from our Github repository and reference it in your project or, if you have the Node package manager installed, you can download it automatically by running ``` $ npm install @klangoo/magnetapiclient ``` Once you have the Magnet API Client properly referenced in your project, you can start sending calls to the API in your code. For sample implementations, check the NLP sample.

Dependencies

Magnet API Client uses the following Node built in Libraries:
Usage
This quick start tutorial will show you how to process a text

Initialize the client

To begin, you will need to initialize the client. In order to do this you will need your API Key CALK and Secret Key. You can find both on your Klangoo account. ```javascript let MagnetAPIClient = require('@klangoo/magnetapiclient'); let ENDPOINT = "https://nlp.klangoo.com/Service.svc"; let CALK = "ENTERYOURCALK"; let SECRETKEY = "ENTERYOURSECRETKEY"; let client = new MagnetAPIClient(ENDPOINT, CALK, SECRETKEY); function callAPICallback(methodName) {
let request = { "text" : "Real Madrid transfer news",
"lang" : "en",
"format" : "json" };
client.CallWebMethod(methodName, request, "POST",
function (json) {
console.log("\ncallAPI_Callback(" + methodName + "):");
console.log(json);
});
} function callAPIPromise(methodName) {
let request = { "text" : "Real Madrid transfer news",
"lang" : "en",
"format" : "json" };
client.CallWebMethod("ProcessDocument", request, "POST").then(function(json) {
console.log("\ncallAPI_Promise(" + methodName + "):");
console.log(json); 
}, function(err) {
console.log("Error occurred: " + err); 
});
} async function callAPI
Async(methodName) {
let request = { "text" : "Real Madrid transfer news",
"lang" : "en",
"format" : "json" };
try {
let json = await client.CallWebMethod("ProcessDocument", request, "POST");
console.log("\ncallAPI_Async(" + methodName + "):");
console.log(json);
}catch(err){
console.log("Error occurred: " + err); 
}
} // // main // callAPICallback("ProcessDocument"); callAPIPromise("ProcessDocument"); callAPIAsync("ProcessDocument"); ```