Detect Hate Speech from Text in Swift

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)let parameters = "TextToAnalyze=%3Cstring%3E"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/nlp-v2/analytics/hate-speech")!,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()

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Solving: import error can’t determine version for bottleneck .

How to convert a Word DOCX Document to Text TXT in Python

Docker Container Part-1.

FORENSIC ENGINEERS CASE FILE

How to secure NGINX (SSL Certificate) with let’s Encryption by Certbot client on Ububtu 16.04

How to Decrypt and Password-Protect a PDF using Java

Unity2D DevLog 03 — Improving the Shield PowerUp

JupyterLab is Ready for Users

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

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

More from Medium

Publishing to the Google Play Store with Fastlane and GitHub Actions

Firebase Cloud Firestore Import Export JSON CSV Data with Ease | Refi App GUI tool for Firestore

Flutter Push Notification HMS Push Kit With One Signal

Opensource licenses monitoring with Sonarqube