lib/calais-entity-extractor.js
function (cb, text) {
        var calais = this;

        if (!calais.validateOptions())
            return cb({}, 'Bad options');

        if (this._undefinedOrNull(text) || typeof text != 'string' || text.length == 0)
            text = this.options.content;
        if (this._undefinedOrNull(text) || typeof text != 'string' || text.length == 0)
            return cb({}, 'No text given in options or parameter');


        var params = {
            'Host'                   : calais.options.apiHost,
            'x-ag-access-token'      : calais.apiKey,
            'x-calais-language'      : calais.options.language,
            'Content-Type'           : calais.options.contentType,
            'Accept'                 : 'application/json',
            'Content-Length'         : text.length,
            'OutputFormat'           : 'application/json'
        }


        var options = {
            uri    : 'https://' + calais.options.apiHost + calais.options.apiPath,
            method : 'POST',
            body   : text,
            headers: params
        };


        //Send the response
        request(options, function (error, response, calaisData) {
            if (error)
                return cb({}, error);

            if (response === undefined) {
                return cb({}, 'Undefined Calais response');
            } else if (response.statusCode === 200) {
                if (!calaisData)
                    return cb({}, calais.errors);

                try {
                    // parse to a Javascript object if requested
                    var result = JSON.parse(calaisData);
                    result = (typeof result === 'string') ? JSON.parse(result) : result;

                    var parsedResult;
                    if (calais.options.parseData) {
                        parsedResult = calais._parseCalaisData(result, calais.options.minConfidence);
                    } else {
                        parsedResult = result;
                    }

                    return cb(parsedResult, calais.errors);
                } catch(e) {
                    return cb({}, e);
                }
            } else
                return cb({}, 'Request error: ' + (typeof response === 'string' ? response : JSON.stringify(response)));

        });
    }
function (cb, text) {
        var calais = this;

        if (!calais.validateOptions())
            return cb({}, 'Bad options');

        if (this._undefinedOrNull(text) || typeof text != 'string' || text.length == 0)
            text = this.options.content;
        if (this._undefinedOrNull(text) || typeof text != 'string' || text.length == 0)
            return cb({}, 'No text given in options or parameter');


        var params = {
            'Host'                   : calais.options.apiHost,
            'x-ag-access-token'      : calais.apiKey,
            'x-calais-language'      : calais.options.language,
            'Content-Type'           : calais.options.contentType,
            'Accept'                 : 'application/json',
            'Content-Length'         : text.length,
            'OutputFormat'           : 'application/json'
        }


        var options = {
            uri    : 'https://' + calais.options.apiHost + calais.options.apiPath,
            method : 'POST',
            body   : text,
            headers: params
        };


        //Send the response
        request(options, function (error, response, calaisData) {
            if (error)
                return cb({}, error);

            if (response === undefined) {
                return cb({}, 'Undefined Calais response');
            } else if (response.statusCode === 200) {
                if (!calaisData)
                    return cb({}, calais.errors);

                try {
                    // parse to a Javascript object if requested
                    var result = JSON.parse(calaisData);
                    result = (typeof result === 'string') ? JSON.parse(result) : result;

                    var parsedResult;
                    if (calais.options.parseData) {
                        parsedResult = calais._parseCalaisData(result, calais.options.minConfidence);
                    } else {
                        parsedResult = result;
                    }

                    return cb(parsedResult, calais.errors);
                } catch(e) {
                    return cb({}, e);
                }
            } else
                return cb({}, 'Request error: ' + (typeof response === 'string' ? response : JSON.stringify(response)));

        });
    }
function ( cb , text ) { var calais = this ; if ( ! calais . validateOptions ( ) ) return cb ( { } , 'Bad options' ) ; if ( this . _undefinedOrNull ( text ) || typeof text != 'string' || text . length == 0 ) text = this . options . content ; if ( this . _undefinedOrNull ( text ) || typeof text != 'string' || text . length == 0 ) return cb ( { } , 'No text given in options or parameter' ) ; var params = { 'Host' : calais . options . apiHost , 'x-ag-access-token' : calais . apiKey , 'x-calais-language' : calais . options . language , 'Content-Type' : calais . options . contentType , 'Accept' : 'application/json' , 'Content-Length' : text . length , 'OutputFormat' : 'application/json' } var options = { uri : 'https://' + calais . options . apiHost + calais . options . apiPath , method : 'POST' , body : text , headers : params } ; //Send the response request ( options , function ( error , response , calaisData ) { if ( error ) return cb ( { } , error ) ; if ( response === undefined ) { return cb ( { } , 'Undefined Calais response' ) ; } else if ( response . statusCode === 200 ) { if ( ! calaisData ) return cb ( { } , calais . errors ) ; try { // parse to a Javascript object if requested var result = JSON . parse ( calaisData ) ; result = ( typeof result === 'string' ) ? JSON . parse ( result ) : result ; var parsedResult ; if ( calais . options . parseData ) { parsedResult = calais . _parseCalaisData ( result , calais . options . minConfidence ) ; } else { parsedResult = result ; } return cb ( parsedResult , calais . errors ) ; } catch ( e ) { return cb ( { } , e ) ; } } else return cb ( { } , 'Request error: ' + ( typeof response === 'string' ? response : JSON . stringify ( response ) ) ) ; } ) ; }
Perform the analysis request with Calais. If no |text| is given or |text| is empty,
then we fall back to the set options.content value. If that is also empty, an error is
returned.

@param cb Callback function of form function(resultData, error);
@param text Optional, the text to perform extraction on. If not set, the options.content
value is used.
@returns nothing
Perform the analysis request with Calais . If no |text| is given or |text| is empty then we fall back to the set options . content value . If that is also empty an error is returned .