@klangoo/magnetapiclient

1.1.0 • Public • Published

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.

let MagnetAPIClient = require('@klangoo/magnetapiclient');

let ENDPOINT = "https://nlp.klangoo.com/Service.svc";
let CALK = "ENTER_YOUR_CALK";
let SECRET_KEY = "ENTER_YOUR_SECRET_KEY";

let client = new MagnetAPIClient(ENDPOINT, CALK, SECRET_KEY);

function callAPI_Callback(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 callAPI_Promise(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
//
callAPI_Callback("ProcessDocument");

callAPI_Promise("ProcessDocument");

callAPI_Async("ProcessDocument");

Readme

Keywords

Package Sidebar

Install

npm i @klangoo/magnetapiclient

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

22.2 kB

Total Files

7

Last publish

Collaborators

  • klangoo