Skip to content

A Ktor-based Profanity Filter HTTP API, integrated into Android and iOS using Kotlin Multiplatform (KMP), that detects and censors profane words and returns the original text, censored output, and a profanity flag.

Notifications You must be signed in to change notification settings

sanjaydraws/ProfanityCensor

Repository files navigation

Profanity Censor API

Profanity Filter API is a simple HTTP API built using Ktor that allows you to filter and censor profane words from input text. It utilizes a customizable list of profane words, and the response includes the original text, the censored version, and a flag indicating whether any profanity was detected.

Features

  • Censors profane words in the input text.
  • Returns the original text, the censored text, and a profanity detection flag.
  • Provides statistics on the number of profane words detected, including counts for each specific word.
  • Supports customizable censorship with options for different replacement characters or strings.
  • Supports JSON input and output.
  • Requires an API key for secure access.

Installation

  1. Clone the repository:
  2. Build the project using Gradle:
  3. Run the application:
  4. The server will start on http://localhost:8080.

API Usage

Endpoint

POST /profanitycensor

Request

You need to send a JSON payload containing the text to be filtered. The API key must be included in the request headers.

Request Headers

  • X-Api-Key: 1febc51b-1493-49f6-a85b-15f684269321.

Request Body

The request body should be a JSON object containing the following parameters:

  • text (string, required): The text that you want to filter for profane words.
  • replacement (string, optional): The character(s) to use for censoring profane words. Defaults to * if not provided.

Example Request Body:

{
   "text": "Why the hell would you do that?",
   "replacement": "*"
}

Example Response

The response will be a JSON object containing the following fields:

  • original (string) : The original input text.
  • censored (string) : The censored version of the text with profane words replaced.
  • has_profanity (boolean) : A flag indicating whether any profanity was detected.
  • statistics (object): An optional field that provides statistics about the profanity detected.
  • totalProfaneWords (integer): The total number of profane words found in the text.
  • profaneWordCounts (object): A map of profane words and their counts.
{
   "original": "Why the hell would you do that?",
   "censored": "Why the **** would you do that?",
   "has_profanity": true,
   "statistics": {
      "totalProfaneWords": 1,
      "profaneWordCounts": {
         "hell": 1
      }
   }
}

About

A Ktor-based Profanity Filter HTTP API, integrated into Android and iOS using Kotlin Multiplatform (KMP), that detects and censors profane words and returns the original text, censored output, and a profanity flag.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published