Textrics API Stack


Emotion Analysis API Implementation

This API works on a sentence and tells us the emotion of given text in the form of Happy, Sad, Anger or Fear. Given a short sentence, it returns a label representing the identified emotion, along with a numeric confidence score.

Endpoint

https://api.textrics.ai/emotion_file_analysis.php

We support POST method to communicate with API.

Parameters

1. dataset - This parameter is required
This is the upload file name which you wish to send to application to analyse.

2. api_key - This parameter is required
This is used to identify the user and the active subscription plan.

3. api_token - This parameter is required
This is used to authenticate the above user account.

4. language - This parameter is required
This is used to detect language of sentence in file.

API Script

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $cfile = new CURLFile(                                // input file  containing text //
        $_FILES['dataset']['tmp_name'],
        $_FILES['dataset']['type'],
        $_FILES['dataset']['name']
        );		           
	
        $apiUrl = 'https://api.textrics.ai/emotion_file_analysis.php';		// API URL //
        $args['language'] = $_POST['language'];            // Pass language  used in file// 
	    $args['dataset'] = $cfile;                                       // pass uploaded file object //
	    $args['col_name'] = $_POST['col_name'];                // Pass Column Name used in file//
	    $args['api_key'] = 'A32NBK55K3'; 		// user specific key to validate the account //
	    $args['api_token'] = 'P4lwpqT0YZYSVefSh44ADkvlJ8pesZDI';   // respective token to validate user credentials //
	

    $options=[
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POSTFIELDS => $args,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_HTTPHEADER => ['Content-Type: multipart/form-data']
      ];
    $ch = curl_init($apiUrl);
    curl_setopt_array($ch, $options);
    $response1 = curl_exec($ch);
    echo $err = curl_error($ch); 
    curl_close($ch);	
    $response =  json_decode($response1,true);		// API output is stored in $response variable //
	
}

?>

Sample of retrieving the output

<?php
if(!empty($response))
{
    echo "<br/>";
	echo "Response";
	echo "<br/>";
	echo "<pre style='text-align:left;'>"; 
	print_r($response);				// Printing the $response output on page //
	echo "</pre>"; 
}
if(!empty($message))
{
	echo $message;
}

?>

Response Format

The response is structured in JSON as follows:

Array
(
    [response] => 1
    [data] => Array
        (
            [0] => Array
                (
                    [Sentence] => Our track record in developing innovations that are valued by the market is poor.  We spend too much time talking about our previous wins (innovations that were developed many years ago, sometimes over a decade ago).  There are often too many opinions / gatekeepers, design (of value propositions, pricing approach and sometimes even feature set) by committee is prevalent.  Highly collaborative / "No blame" culture has all but eliminated individual accountability on a major project level.
                    [Prediction] => Sad
                    [Confidence] => 45.0960960388
                    [wordcloud] => Array
                        (
                            [0] => track
                            [1] => record
                            [2] => developing
                            [3] => innovations
                            [4] => valued
                            [5] => market
                            [6] => poor.
                            [7] => spend
                            [8] => time
                            [9] => talking
                            [10] => previous
                            [11] => wins
                            [12] => (innovations
                            [13] => developed
                            [14] => years
                            [15] => ago,
                            [16] => decade
                            [17] => ago).
                            [18] => opinions
                            [19] => /
                            [20] => gatekeepers,
                            [21] => design
                            [22] => (of
                            [23] => propositions,
                            [24] => pricing
                            [25] => approach
                            [26] => feature
                            [27] => set)
                            [28] => committee
                            [29] => prevalent.
                            [30] => highly
                            [31] => collaborative
                            [32] => /
                            [33] => "no
                            [34] => blame"
                            [35] => culture
                            [36] => eliminated
                            [37] => individual
                            [38] => accountability
                            [39] => major
                            [40] => project
                            [41] => level.
                        )
                )

            [1] => Array
                (
                    [Sentence] => I am not aware of "cost to serve" models that have been developed; believe we could gain valuable information on if we spent some time truly understanding the direct costs by customer type to better direct human resources, financial resources, time and energy.
                    [Prediction] => Sad
                    [Confidence] => 38.0846939087
                    [wordcloud] => Array
                        (
                            [0] => not
                            [1] => aware
                            [2] => "cost
                            [3] => serve"
                            [4] => models
                            [5] => developed;
                            [6] => gain
                            [7] => valuable
                            [8] => information
                            [9] => spent
                            [10] => time
                            [11] => understanding
                            [12] => direct
                            [13] => costs
                            [14] => customer
                            [15] => type
                            [16] => direct
                            [17] => human
                            [18] => resources,
                            [19] => financial
                            [20] => resources,
                            [21] => time
                            [22] => energy.
                        )
                )

            [2] => Array
                (
                    [Sentence] => We have a significant weakness with large-scale production single family Builders, relative to our main facing competition - Moen
This hurts us overall as the Single Family Builder market has been particularly strong as of late.
                    [Prediction] => Sad
                    [Confidence] => 71.1819763184
                    [wordcloud] => Array
                        (
                            [0] => significant
                            [1] => weakness
                            [2] => large-scale
                            [3] => production
                            [4] => single
                            [5] => family
                            [6] => builders,
                            [7] => relative
                            [8] => main
                            [9] => facing
                            [10] => competition
                            [11] => -
                            [12] => moen
                            [13] => hurts
                            [14] => single
                            [15] => family
                            [16] => builder
                            [17] => market
                            [18] => strong
                            [19] => late.
                        )
                )

            [3] => Array
                (
                    [Sentence] => Areas to improve:  understanding the Pro segment who shops at retail.
                    [Prediction] => Happy
                    [Confidence] => 50.6046638489
                    [wordcloud] => Array
                        (
                            [0] => areas
                            [1] => improve:
                            [2] => understanding
                            [3] => pro
                            [4] => segment
                            [5] => shops
                            [6] => retail.
                        )
                )

            [4] => Array
                (
                    [Sentence] => We would benefit from a more cohesive company pricing strategy. The segments are empowered to make these decisions, and they can be rather siloed as a result. 
                    [Prediction] => Sad
                    [Confidence] => 48.6785697937
                    [wordcloud] => Array
                        (
                            [0] => benefit
                            [1] => cohesive
                            [2] => company
                            [3] => pricing
                            [4] => strategy.
                            [5] => segments
                            [6] => empowered
                            [7] => make
                            [8] => decisions,
                            [9] => siloed
                            [10] => result.
                        )
                )

            [5] => Array
                (
                    [Sentence] => While we address customer segments effectively we do not effectively bridge these segments which can create channel conflict.
                    [Prediction] => Sad
                    [Confidence] => 42.4309120178
                    [wordcloud] => Array
                        (
                            [0] => address
                            [1] => customer
                            [2] => segments
                            [3] => effectively
                            [4] => not
                            [5] => effectively
                            [6] => bridge
                            [7] => segments
                            [8] => create
                            [9] => channel
                            [10] => conflict.
                        )
                )

            [6] => Array
                (
                    [Sentence] => I believe we look at the business segments and develop strategies around trade and retail.  However, in trade there are many segments. We develop programs and products for "all trade". The market is very different for hospitality or urban high rise compared to what the homeowner wants through the showroom for their personal space. We don't have capabilities to have that flexibility.  Our design team is amazingly talented but they are designing for the entire organization and we see too many similarities in design from one segment to the other (retail and trade overlap in particular) 
                    [Prediction] => Happy
                    [Confidence] => 70.1142272949
                    [wordcloud] => Array
                        (
                            [0] => business
                            [1] => segments
                            [2] => develop
                            [3] => strategies
                            [4] => trade
                            [5] => retail.
                            [6] => however,
                            [7] => trade
                            [8] => segments.
                            [9] => develop
                            [10] => programs
                            [11] => products
                            [12] => "all
                            [13] => trade".
                            [14] => market
                            [15] => hospitality
                            [16] => urban
                            [17] => high
                            [18] => rise
                            [19] => compared
                            [20] => homeowner
                            [21] => showroom
                            [22] => personal
                            [23] => space.
                            [24] => capabilities
                            [25] => flexibility.
                            [26] => design
                            [27] => team
                            [28] => amazingly
                            [29] => talented
                            [30] => designing
                            [31] => entire
                            [32] => organization
                            [33] => similarities
                            [34] => design
                            [35] => segment
                            [36] => (retail
                            [37] => trade
                            [38] => overlap
                            [39] => particular)
                        )
                )

            [7] => Array
                (
                    [Sentence] => I would challenge at times the in depth view of our customer views.
                    [Prediction] => Happy
                    [Confidence] => 55.4181976318
                    [wordcloud] => Array
                        (
                            [0] => challenge
                            [1] => times
                            [2] => depth
                            [3] => view
                            [4] => customer
                            [5] => views.
                        )
                )

            [8] => Array
                (
                    [Sentence] => A challenge I see is overlapping brands competing for the same business, and at times, driving the decision down to price...in essence, commoditizing our own products. I also see efforts in the field creating a mash-up of the brands, diluting the value each brings to the customer.
                    [Prediction] => Happy
                    [Confidence] => 76.4596099854
                    [wordcloud] => Array
                        (
                            [0] => challenge
                            [1] => overlapping
                            [2] => brands
                            [3] => competing
                            [4] => business,
                            [5] => times,
                            [6] => driving
                            [7] => decision
                            [8] => price...in
                            [9] => essence,
                            [10] => commoditizing
                            [11] => products.
                            [12] => efforts
                            [13] => field
                            [14] => creating
                            [15] => mash-up
                            [16] => brands,
                            [17] => diluting
                            [18] => brings
                            [19] => customer.
                        )
                )
        )

    [message] => success
)

API Response Codes

Code Interpretation
1 Success
Exception Codes
10 Authentication Exception
11 Invalid Input Exception
12 Language Exception
13 File Format Error
14 Request Timeout
15 Column Name Mismatch
99 Other Exception