Quick and easy

text2data api

Our platform provides Restful API supporting the most popular formats; JSON and XML. We use cloud computing with auto scale configuration to ensure robust infrastructure you can rely on. In order to start processing documents, you need to get api key from us. You will find the key in your administration panel once you register.


Register, get the api key and play with api directly on the web

swagger Swagger: http://api.text2data.com/swagger/ui/


Please download below code samples to start integrating your systems with our API (.NET)





Nuget package installation


                      
                     PM> Install-Package Text2data.com.SentimentAnalysis.Api -Version 3.5.3
                      
                    

Code samples [api v3]

                            //C# code sample when using our SDK

                            var inputText = "Excellent location, opposite a very large mall with wide variety of shops, restaurants and more.";
                            var privateKey = "---------------------"; //add your private key here (you can find it in the admin panel once you sign-up)
                            var secret = ""; //this should be set-up in admin panel as well

                            // Create request object
                            var doc = new Document()
                                {
                                    DocumentText = inputText,
                                    IsTwitterContent = false,
                                    UserCategoryModelName = "", //name of your trained model, leave empty for default
                                    PrivateKey = privateKey,
                                    Secret = secret,
                                    RequestIdentifier = "" //optional, used for reporting context
                                };

                            var docResult = API.GetDocumentAnalysisResult(doc); //execute request
                            if (docResult.Status == (int)DocumentResultStatus.OK) //check status
                            {
                                // display document level score
                                Console.WriteLine(string.Format("This document is: {0}{1} {2}", docResult.DocSentimentPolarity, docResult.DocSentimentResultString, docResult.DocSentimentValue.ToString("0.00")));
                                Console.WriteLine(string.Format("Magnitude: {0}", docResult.Magnitude.ToString("0.00")));
                                Console.WriteLine(string.Format("Subjectivity: {0}", docResult.Subjectivity));

                                // display themes if any found
                                if (docResult.Themes != null && docResult.Themes.Any())
                                {
                                    Console.WriteLine(Environment.NewLine + "Themes:");
                                    foreach (var theme in docResult.Themes)
                                    {
                                        Console.WriteLine(string.Format("{0} ({1}) {2}{3} {4}", theme.Text, theme.KeywordType, theme.SentimentPolarity, theme.SentimentResult, theme.SentimentValue.ToString("0.00")));
                                    }
                                }

                                // display entity scores if any found
                                if (docResult.Entities != null && docResult.Entities.Any())
                                {
                                    Console.WriteLine(Environment.NewLine + "Entities:");
                                    foreach (var entity in docResult.Entities)
                                    {
                                        Console.WriteLine(string.Format("{0} ({1}) {2}{3} {4}", entity.Text, entity.KeywordType, entity.SentimentPolarity, entity.SentimentResult, entity.SentimentValue.ToString("0.00")));
                                    }
                                }

                                // display keyword scores if any found

                                if (docResult.Keywords != null && docResult.Keywords.Any())
                                {
                                    Console.WriteLine(Environment.NewLine + "Keywords:");
                                    foreach (var keyword in docResult.Keywords)
                                    {
                                        Console.WriteLine(string.Format("{0} ({1}) {2}{3} {4}", keyword.Text, keyword.KeywordType, keyword.SentimentPolarity, keyword.SentimentResult, keyword.SentimentValue.ToString("0.00")));
                                    }
                                }

                                //display more information below if required 
                                //...
                            }
                            else
                            {
                                Console.WriteLine(docResult.ErrorMessage);
                            }

                            Console.ReadLine();
                            
                                //VB.NET code sample when using our SDK

                                Dim inputText As String = "Excellent location, opposite a very large mall with wide variety of shops, restaurants and more."
                                Dim privateKey As String = "-------------------------" 'add your private key here (you can find it in the admin panel once you sign-up)
                                Dim secret As String = ""  'this should be set-up in admin panel as well

                                Dim doc = New Document() With {.DocumentText = inputText, .IsTwitterContent = False, .UserCategoryModelName = "", .PrivateKey = privateKey, .Secret = secret, .RequestIdentifier = ""}
                                Dim docResult = API.GetDocumentAnalysisResult(doc) 'execute request

                                If docResult.Status = CInt(DocumentResultStatus.OK) Then 'check status
                                    'display document level score
                                    Console.WriteLine(String.Format("This document is: {0}{1} {2}", docResult.DocSentimentPolarity, docResult.DocSentimentResultString, docResult.DocSentimentValue.ToString("0.000")))
                                    Console.WriteLine(String.Format("Magnitude: {0}", docResult.Magnitude.ToString("0.000")))
                                    Console.WriteLine(String.Format("Subjectivity: {0}", docResult.Subjectivity))

                                    If docResult.Themes IsNot Nothing AndAlso docResult.Themes.Any() Then
                                        Console.WriteLine(Environment.NewLine + "Themes:")
                                        For Each theme As SentencePart In docResult.Themes
                                            Console.WriteLine(String.Format("{0} ({1}) {2}{3} {4}", theme.Text, theme.KeywordType, theme.SentimentPolarity, theme.SentimentResult, theme.SentimentValue.ToString("0.0000")))
                                        Next
                                    End If

                                    If docResult.Entities IsNot Nothing AndAlso docResult.Entities.Any() Then
                                        Console.WriteLine(Environment.NewLine + "Entities:")
                                        For Each entity As SentencePart In docResult.Entities
                                            Console.WriteLine(String.Format("{0} ({1}) {2}{3} {4}", entity.Text, entity.KeywordType, entity.SentimentPolarity, entity.SentimentResult, entity.SentimentValue.ToString("0.0000")))
                                        Next
                                    End If

                                    If docResult.Keywords IsNot Nothing AndAlso docResult.Keywords.Any() Then
                                        Console.WriteLine(Environment.NewLine + "Keywords:")
                                        For Each keyword As SentencePart In docResult.Keywords
                                            Console.WriteLine(String.Format("{0} ({1}) {2}{3} {4}", keyword.Text, keyword.KeywordType, keyword.SentimentPolarity, keyword.SentimentResult, keyword.SentimentValue.ToString("0.0000")))
                                        Next
                                    End If

                                    'display more information below if required 
                                Else
                                    Console.WriteLine(docResult.ErrorMessage)
                                End If

                                Console.ReadLine()
                             
                                
                               var requestDto = new
                                {
                                    DocumentText = "Excellent location, opposite a very large mall with wide variety of shops, restaurants and more.",
                                    IsTwitterContent = false,
                                    UserCategoryModelName = "",
                                    PrivateKey = "----------",//add your private key here (you can find it in the admin panel once you sign-up)
                                    Secret = "", //this should be set-up in admin panel as well
                                    RequestIdentifier = "" //optional, used for reporting context
                                };

                                dynamic responseData;

                                //////make request
                                var request = (HttpWebRequest)WebRequest.Create("http://api.text2data.com/v3/analyze");
                                request.Method = "POST";
                                request.Headers.Add("Accept-Encoding", "gzip,deflate");
                                request.ContentType = "application/json";

                                using (var requestWriter = new StreamWriter(request.GetRequestStream()))
                                {
                                    requestWriter.Write(new JavaScriptSerializer().Serialize(requestDto));
                                }

                                var response = (HttpWebResponse)request.GetResponse();
                                using (var resStream = response.GetResponseStream())
                                {
                                    using (var reader = new StreamReader(resStream))
                                    {
                                        responseData = new JavaScriptSerializer().DeserializeObject(reader.ReadToEnd());
                                    }
                                }

                                ///display received data
                                if (responseData != null && responseData["Status"] == 1)
                                {
                                    Console.WriteLine(string.Format("This document is: {0}{1} {2}", responseData["DocSentimentPolarity"], responseData["DocSentimentResultString"], responseData["DocSentimentValue"].ToString("0.00")));
                                    Console.WriteLine(string.Format("Magnitude: {0}", responseData["Magnitude"].ToString("0.00")));
                                    Console.WriteLine(string.Format("Subjectivity: {0}", responseData["Subjectivity"]));

                                    Console.WriteLine(Environment.NewLine + "Themes:");
                                    foreach (var theme in responseData["Themes"])
                                    {
                                        Console.WriteLine(string.Format("{0} ({1}) {2}{3} {4}", theme["Text"], theme["KeywordType"], theme["SentimentPolarity"], theme["SentimentResult"], theme["SentimentValue"].ToString("0.00")));
                                    }

                                    Console.WriteLine(Environment.NewLine + "Keywords:");
                                    foreach (var keyword in responseData["Keywords"])
                                    {
                                        Console.WriteLine(string.Format("{0} ({1}) {2}{3} {4}", keyword["Text"], keyword["KeywordType"], keyword["SentimentPolarity"], keyword["SentimentResult"], keyword["SentimentValue"].ToString("0.00")));
                                    }
                                }
                                else
                                {
                                    Console.WriteLine(responseData["ErrorMessage"]);
                                }

                                Console.ReadLine();
                           
                                import java.io.BufferedReader;
                                import java.io.IOException;
                                import java.io.InputStreamReader;
                                import org.apache.http.HttpResponse;
                                import org.apache.http.client.HttpClient;
                                import org.apache.http.client.methods.HttpPost;
                                import org.apache.http.entity.ContentType;
                                import org.apache.http.entity.StringEntity;
                                import org.apache.http.impl.client.HttpClientBuilder;
                                import org.json.JSONObject;

                                public class mainClass {
    
                                    public static void main(String[] args) throws IOException {
        
                                           String documentText = "Excellent location, opposite a very large mall with wide variety of shops, restaurants and more.";
                                           String isTwitter = "false";
                                           String userCategoryModelName = "";
                                           String privateKey = "-----------";//add your private key here (you can find it in the admin panel once you sign-up)
                                           String secret = "";//this should be set-up in admin panel as well
                                           /////// 
       
                                           String payload = "{" +
                                                                "\"DocumentText\":\"" + documentText + "\", " +
                                                                "\"IsTwitterContent\":\"" + isTwitter + "\", " +
                                                                "\"UserCategoryModelName\":\"" + userCategoryModelName + "\", " +
                                                                "\"PrivateKey\":\"" + privateKey + "\", " +
                                                                "\"Secret\":\"" + secret + "\", " +
                                                                "\"RequestIdentifier\":\"" + "" + "\" " +
                                                            "}";
                                            //make request
                                            StringEntity entity = new StringEntity(payload, ContentType.create("application/json"));
                                            HttpClient httpClient = HttpClientBuilder.create().build();
                                            HttpPost post = new HttpPost("http://api.text2data.com/v3/analyze");
                                            post.setEntity(entity);

                                            HttpResponse response = httpClient.execute(post); //execute request
                                            BufferedReader readBuffer = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

	                                        StringBuilder result = new StringBuilder();
	                                        String line = "";
	                                         while ((line = readBuffer.readLine()) != null) {
		                                        result.append(line);
	                                         }   
  
                                            JSONObject jsonObj = new JSONObject(result.toString());
                                            int status = (int)jsonObj.get("Status");
        
                                            //display results
                                            if(status == 1)
                                            {
                                               System.out.println(String.format("This document is: %1s%2s %3.2f", jsonObj.getString("DocSentimentPolarity"), jsonObj.getString("DocSentimentResultString"), jsonObj.get("DocSentimentValue")));
                                               System.out.println(String.format("Magnitude: %1.2f", jsonObj.getString("Magnitude")));
                                               System.out.println(String.format("Subjectivity: %1s", jsonObj.getString("Subjectivity")));
           
                                                System.out.println("Themes:");   
                                                for (Object item : jsonObj.getJSONArray("Themes")) {
                                                    JSONObject arrObj = (JSONObject)item;
                                                    System.out.println(String.format("%1s (%2s) %3s%4s %5.2f", arrObj.getString("Text"), arrObj.getString("KeywordType"), arrObj.getString("SentimentPolarity"), arrObj.getString("SentimentResult"), arrObj.get("SentimentValue")));
                                                }
           
                                                System.out.println("Entities:");   
                                                for (Object item : jsonObj.getJSONArray("Entities")) {
                                                    JSONObject arrObj = (JSONObject)item;
                                                    System.out.println(String.format("%1s (%2s) %3s%4s %5.2f", arrObj.getString("Text"), arrObj.getString("KeywordType"), arrObj.getString("SentimentPolarity"), arrObj.getString("SentimentResult"), arrObj.get("SentimentValue")));
                                                }
            
                                                System.out.println("Keywords:");   
                                                for (Object item : jsonObj.getJSONArray("Keywords")) {
                                                    JSONObject arrObj = (JSONObject)item;
                                                    System.out.println(String.format("%1s (%2s) %3s%4s %5.2f", arrObj.getString("Text"), arrObj.getString("KeywordType"), arrObj.getString("SentimentPolarity"), arrObj.getString("SentimentResult"), arrObj.get("SentimentValue")));
                                                }
            
                                                //display more information below if required
                                                //...
                                            }
                                            else          
                                            {
                                               System.out.println(jsonObj.get("ErrorMessage")); 
                                            }
                                        }   
                                    }
                           
                            import requests
                            import json

                            url = 'http://api.text2data.com/v3/analyze'
                            payload = {
	                            'DocumentText': 'Excellent location, opposite a very large mall with wide variety of shops, restaurants and more.', 
	                            'IsTwitterContent': 'false',
	                            'PrivateKey': '------------', #add your private key here (you can find it in the admin panel once you sign-up)
	                            'Secret':'', #this should be set-up in admin panel as well
                                'RequestIdentifier': '' #optional, used for reporting context
                            }

                            r = requests.post(url, data=payload)
                            data=r.json()

                            if data['Status'] == 1:
                               print('This document is: %s%s %+.2f' % (data['DocSentimentPolarity'], data['DocSentimentResultString'],data['DocSentimentValue']))
                               print('Magnitude: %.2f' %(data['Magnitude']))
                               print('Subjectivity: %s' %(data['Subjectivity']))
  
                               print('Themes')
   
                               for item in data['Themes']:
                                 print('%s (%s) %s%s %+.2f' %(item['Text'], item['KeywordType'], item['SentimentPolarity'], item['SentimentResult'], item['SentimentValue']))
	 
                               print('Entities')
   
                               for item in data['Entities']:
                                 print('%s (%s) %s%s %+.2f' %(item['Text'], item['KeywordType'], item['SentimentPolarity'], item['SentimentResult'], item['SentimentValue']))
	 
                               print('Keywords')
   
                               for item in data['Keywords']:
                                 print('%s (%s) %s%s %+.2f' %(item['Text'], item['KeywordType'], item['SentimentPolarity'], item['SentimentResult'], item['SentimentValue']))
	 
	                            #display more information below if required
                                #...
 
                            else: 
                               print(data['ErrorMessage'])
                               
                            
                                library(httr)

                                url <- "http://api.text2data.com/v3/analyze"
                                       requestBody <- list(
                                  DocumentText = "Excellent location, opposite a very large mall with wide variety of shops, restaurants and more.",
                                  IsTwitterContent = "false",
                                  UserCategoryModelName = "",
                                  PrivateKey = "------------",#add your private key here (you can find it in the admin panel once you sign-up)
                                  Secret= "", #this should be set-up in admin panel as well
                                  RequestIdentifier = "" #optional, used for reporting context
                                )
                                #make POST request
                                res <- httr::POST(url = url,body = requestBody, encode = "json")

                                #read response
                                json <- httr::content(res, as = "text")
                                respData <- jsonlite::fromJSON(json)

                                #display results
                                if(respData$Status == 1)
                                {
	                                print(
	                                 sprintf("This document is: %s %s%.2f", respData$DocSentimentResultString, respData$DocSentimentPolarity, respData$DocSentimentValue)
	                                )
	                                print(
	                                 sprintf("Magnitude is: %.2f", respData$Magnitude)
	                                )
	                                print(
	                                 sprintf("Subjectivity is: %s", respData$Subjectivity)
	                                )


                                } else{
                                   print(respData$ErrorMessage)
                                }
                            
                                 
                               curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ 
                               "DocumentText": "Excellent location, opposite a very large mall with wide variety of shops, restaurants and more.", \ 
                               "IsTwitterContent": false, \ 
                               "PrivateKey": "your api key here", \ 
                               "Secret": "your secret here", \ 
                               "UserCategoryModelName": "", \ 
                               "DocumentLanguage": "en", \ 
                               "SerializeFormat": 1, \ 
                               "RequestIdentifier": "" \
                               }' 'http://api.text2data.com/v3/analyze'
                              
                            

                     
                     API url (shared): http://api.text2data.com/v3/analyze
                     API url (custom endpoint): http(s)://your_company.text2data.com/v3/analyze
                     
                    
                    //enums

                    DocumentResultStatus:
                        OK = 1,
                        AuthenticationFailure = 2,
                        CreditExceeded = 3, //top up required
                        ServiceBusy = 4,
                        ValidationError = 5,
                        GenericError = 6

                    SerializeFormats:
                        Json = 1,
                        Xml = 2
                      
                     

Document categorization service

Document categorization service allows you analyzing big documents quicker as it only returns auto categories and user categories data. Post and return object structure is the same as for "analyze" method.

You can use it e.g. to filter down the data prior performing full analysis.

                     
                     Categorization service url (shared): http://api.text2data.com/v3/categorize
                     Categorization service url (custom endpoint): http(s)://your_company.text2data.com/v3/categorize
                     
                    

Following samples show request and response objects in JSON.

Post object

                                        {
                                          "DocumentText": "string", //text to be analysed
                                          "IsTwitterContent": false, //Twitter mode setting
                                          "PrivateKey": "string",   // private key, can be found in admin panel
                                          "Secret": "string",  //api password, can be set in admin panel
                                          "UserCategoryModelName": "string", //custom category model (optional)
                                          "DocumentLanguage": "string", //"en" by default (english only is supported)
                                          "SerializeFormat": 1, //json(1) or xml(2)
                                          "RequestIdentifier": "" //optional, used for reporting context
                                        }
                      

Response object

                                 {
                                  "DocSentimentResultString": "string",
                                  "DocSentimentValue": 0,
                                  "DocSentimentPolarity": "string",
                                  "Magnitude": 0,
                                  "Entities": [
                                    {
                                      "Text": "string",
                                      "SentenceText": "string",
                                      "Mentions": 0,
                                      "Magnitude": 0,
                                      "SentencePartType": "string",
                                      "KeywordType": "string",
                                      "SentimentResult": "string",
                                      "SentimentValue": 0,
                                      "SentimentPolarity": "string"
                                    }
                                  ],
                                  "Themes": [
                                    {
                                      "Text": "string",
                                      "SentenceText": "string",
                                      "Mentions": 0,
                                      "Magnitude": 0,
                                      "SentencePartType": "string",
                                      "KeywordType": "string",
                                      "SentimentResult": "string",
                                      "SentimentValue": 0,
                                      "SentimentPolarity": "string"
                                    }
                                  ],
                                  "Keywords": [
                                    {
                                      "Text": "string",
                                      "SentenceText": "string",
                                      "Mentions": 0,
                                      "Magnitude": 0,
                                      "SentencePartType": "string",
                                      "KeywordType": "string",
                                      "SentimentResult": "string",
                                      "SentimentValue": 0,
                                      "SentimentPolarity": "string"
                                    }
                                  ],
                                  "Citations": [
                                    {
                                      "Text": "string",
                                      "SentenceText": "string",
                                      "Mentions": 0,
                                      "Magnitude": 0,
                                      "SentencePartType": "string",
                                      "KeywordType": "string",
                                      "SentimentResult": "string",
                                      "SentimentValue": 0,
                                      "SentimentPolarity": "string"
                                    }
                                  ],
                                  "SlangWords": [
                                    {
                                      "SlangWordText": "string",
                                      "SlangWordTranslation": "string"
                                    }
                                  ],
                                  "SwearWords": [
                                    {
                                      "SlangWordText": "string",
                                      "SlangWordTranslation": "string"
                                    }
                                  ],
                                  "CoreSentences": [
                                    {
                                      "SentenceNumber": 0,
                                      "Text": "string",
                                      "SentimentResultString": "string",
                                      "SentimentValue": 0,
                                      "SentimentPolarity": "string",
                                      "Relevance": 0,
                                      "Magnitude": 0
                                    }
                                  ],
                                  "PartsOfSpeech": [
                                    {
                                      "Text": "string",
                                      "Subject": "string",
                                      "Action": "string",
                                      "Object": "string",
                                      "ObjectSentimentResultString": "string",
                                      "ObjectSentimentValue": 0,
                                      "ObjectSentimentPolarity": "string"
                                    }
                                  ],
                                  "AutoCategories": [
                                    {
                                      "CategoryName": "string",
                                      "Score": 0
                                    }
                                  ],
                                  "UserCategories": [
                                    {
                                      "CategoryName": "string",
                                      "Score": 0
                                    }
                                  ],
                                  "Subjectivity": "string",
                                  "DetectedLanguage": "string",
                                  "ErrorMessage": "string",
                                  "Status": 0,
                                  "TransactionTotalCreditsLeft": 0,
                                  "TransactionUseByDate": "2019-04-22T11:32:21.332Z",
                                  "TransactionCurrentDay": 0,
                                  "TransactionDailyLimit": 0
                                }
                                    


If you don't have skills to integrate with our platform, we can do it for you. Please contact us for no obligation quote.



Custom API Endpoint

If you need unlimited access/ number of requests per day, we can provide you with completely isolated API engine on the VM with the size and location of your choice.

The diagram below shows how this fits in into your company's IT infrastructure landscape:


custom machine learning api server


If you choose to have your separate endpoint, you will have your custom API url like http(s)://[yourCompanyName].text2data.com
You will then be able to call your endpoint programmatically, using our provided SDK or our Excel Add-In/Google Sheets Add-on by setting-up your custom name in the settings as presented below:


Excel Add-In
Excel settings
Google Sheets Add-on
Google Sheets settings


Please contact us for more details.