How to Paraphrase or Rephrase Text in Swift

Cloudmersive
2 min readMar 27, 2021

--

Advances in Deep Learning AI have provided many exciting opportunities to solve both personal and business problems, and in this short article, we will cover how to use it to paraphrase or rephrase English text. While it would normally take a good deal of training to properly understand and utilize this Deep Learning technology, we have wrapped it up in an API that can be run in Swift. This operation will create 1 to 10 possible rephrasing candidates, which seek to preserve the original meaning of the input sentence(s).

To use the paraphrase/rephrase API, all we need to do is input the rephrase request (including the text to translate and target rephrasing count) and our API key into the example code below:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)let parameters = "TextToTranslate=%3Cstring%3E&TargetRephrasingCount=%3Cinteger%3E"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/nlp-v2/rephrase/rephrase/eng/by-sentence")!,timeoutInterval: Double.infinity)
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()

You will receive your rephrased results in seconds flat; from here you can determine which options you want to use for your writing project. If you need an API key, you can retrieve it for free via the Cloudmersive website; this will give you access to 800 calls/month across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet