Findging synonyms with GroupDocs.Rewriter SDK

Although you can directly call the GroupDocs.Rewriter Cloud REST API to send text and fetch the result, there is a much easier way to implement required functionality in your applications. We provide software development kits (SDKs) for all popular programming languages. They wrap up all routine operations such as establishing connections, sending API requests, and parsing responses into a few simple methods. It makes interaction with GroupDocs.Rewriter Cloud services much easier, allowing you to focus on business logic rather than technical details.

using GroupDocs.Rewriter.Cloud.Sdk.Api;
using GroupDocs.Rewriter.Cloud.Sdk.Client;
using GroupDocs.Rewriter.Cloud.Sdk.Client.Auth;
using GroupDocs.Rewriter.Cloud.Sdk.Model;
using Configuration = GroupDocs.Rewriter.Cloud.Sdk.Client.Configuration;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using System.Net.Http;
using HttpStatusCode = System.Net.HttpStatusCode;
namespace GroupDocs.Rewriter.Cloud.Sdk
{
    public class TextSynonymizer
	  {
		    public TextSynonymizer()
		    {
            Configuration config = new Configuration();
			      config.OAuthFlow = OAuthFlow.APPLICATION;
			      config.OAuthClientId = "YOU_CLIENT_ID";
			      config.OAuthClientSecret = "YOU_CLIENT_SECRET";
            config.BasePath = "https://api.groupdocs.cloud/v2.0/rewriter";
            SynonymizeApi api = new SynonymizeApi(conf);
            string srcText = "YOUR_WORD";
            string sourceLanguage = "en";
            SynonymizeTextResponse response = new SynonymizeTextResponse();
            SynonymizeTextRequest request = new SynonymizeTextRequest(
                language: sourceLanguage,
                text: srcText,
                synonyms: SynonymizeTextRequest.SynonymsEnum.All);
            StatusResponse responseId = await api.SynonymizeTextPostAsync(request);
            try
            {
                if (responseId.Status.ToString() == "Accepted")
                {
                    while (true)
                    {
                        response = await api.SynonymizeTextRequestIdGetAsync(responseId.Id);
                        if (response.Status.ToString() == "OK")
                        {
                            foreach (string synonym in response.SynonymizerResults)
                            {
                                Console.WriteLine($"Synonym for word {srcText}: {synonym}");
                            }
                            break;
                        }
                        else
                            Thread.Sleep(2000);
                    }
                }
                else
                {
                    response = new SynonymizeTextResponse() { Status = responseId.Status, Message = responseId.Message };
                    Console.WriteLine("Text error: " + textResponse.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Text exception: " + ex.ToString());
            }                
        }
    }
}

Visit our GitHub repository for a working code and sample files: https://github.com/groupdocs-rewriter-cloud/groupdocs-rewriter-cloud-dotnet

import time
import groupdocs_rewriter_cloud
from groupdocs_rewriter_cloud.api.synonymize_api import SynonymizeApi 
from groupdocs_rewriter_cloud.rest import ApiException
rom groupdocs_rewriter_cloud.models import SynonymizeTextRequest

api = SummarizeApi()
file_api = FileApi()
api.api_client.configuration.client_id = "CLIENT_ID"
api.api_client.configuration.client_secret = "CLIENT_SECRET"
language = "en"
src_text = "YOUR_TEXT"
request = SynonymizeTextRequest(language=language, text=src_text)
status = api.synonymize_text_post(request)
if status.status == groupdocs_rewriter_cloud.models.HttpStatusCode.ACCEPTED:
    while True:
        text_response = api.synonymize_text_request_id_get(status.id)
        if text_response.status == groupdocs_rewriter_cloud.models.HttpStatusCode.OK:
            for result in text_response.synonymizer_result:
                print(result)
            break
        time.sleep(2)

Visit our GitHub repository for a working code and sample files: https://github.com/groupdocs-rewriter-cloud/groupdocs-rewriter-cloud-python

package com.groupdocs;
// Import classes:

import com.groupdocs.model.*;
import org.openapitools.client.api.SynonymizeApi;

public class Demo {
    public static void main(String[] args) {
        String basePath = "https://api.groupdocs.cloud/v2.0/rewriter";
        String cliendId = "YOUR_CLIENT_ID";
        String clientSecret = "YOUR_CLIENT_SECRET";

        ApiClient defaultClient = new ApiClient(basePath, cliendId, clientSecret, null);
        SynonymizeApi apiInstance = new SynonymizeApi(defaultClient);

        String s = "TEXT_TO_SYNONYMIZE";

        SynonymizeTextRequest request = new SynonymizeTextRequest();
        request.setLanguage("en");
        request.setText(s);

        try {
            StatusResponse response = apiInstance.synonymizeTextPost(request);
            String response_id = response.getId();
            if (!response.getStatus().toString().equals("BadRequest")){
                while (true){
                    SynonymizeTextResponse synonymizeTextResponse = apiInstance.synonymizeTextRequestIdGet(response_id);
                    if (synonymizeTextResponse.getStatus().toString().equals("OK")) {
                        System.out.println(synonymizeTextResponse);
                        break;
                    }
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (ApiException e) {
            System.err.println("Exception when calling SynonymizeApi#synonymizeTextPost");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Visit our GitHub repository for a working code and sample files: https://github.com/groupdocs-rewriter-cloud/groupdocs-rewriter-cloud-java