Giter Site home page Giter Site logo

gasegamer / super-profanity Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 2.0 764 KB

An advanced profanity filter based on phonetics and normal detection that detects swears in 27 different languages!

License: Mozilla Public License 2.0

JavaScript 100.00%
badwordsfilter detect detector language languages n-gram natural-language node-js nodejs profanity

super-profanity's Introduction

Super-Profanity
A profanity filter that lives up to its name.

An advanced profanity filter based on phonetics and normal detection that detects swears in 27 different languages!


  • Tells you what and where swears were detected.
  • A very resistant and effective filter against bypassing attempts.
  • Detects words with special characters such as "@ssh0le".
  • Custom options to help with your needs!

Usage

const { profanity } = require("super-profanity");
const result = profanity(
  "Stick your dentures in your @   ss and go f *c k i n g home laughing."
);
console.log(result);

/*
{
  badWordLanguage: 'en'
  detectedWord: '@  ss'
  isBadWord: true
  profanityWordRelated: 'ass'
}
*/

Main Language

Although it tries its best, super-profanity is far from perfect... Thus, to guarantee that the code will check for swears in a desired language, you have the option to select your main language, which by default is English. The main language will always be checked in the provided sentence.

Use changeMainLanguage if needed.

const { changeMainLanguage } = require("super-profanity");

changeMainLanguage('pt');

/*
Changed main language from en to pt.
*/

Useful functions

Whitelist

Whitelist a word in a specific language.

const { whitelistWord } = require("super-profanity");

// It will whitelist in your mainLanguage by default.
whitelistWord("grass");

/*
grass whitelisted at en.
*/
const { whitelistWord } = require("super-profanity");

// You can change the language in which the word will be added.
whitelistWord("merda", "pt").

/*
merda whitelisted at pt.
*/

Blacklist

Blacklist a word in a specific language.

const { blacklistWord } = require("super-profanity");

// It will blacklist in your mainLanguage by default.
blacklistWord("๐Ÿ–•");

/*
๐Ÿ–• blacklisted at en.
*/
const { blacklistWord } = require("super-profanity");

// You can change the language in which the word will be added.
blacklistWord("๐Ÿ–•", "pt").

/*
๐Ÿ–• blacklisted at pt.
*/

Remove Word

Remove a word in a specific language.

const { removeWord } = require("super-profanity");

// It will remove from your mainLanguage by default.
removeWord("mierda");

/*
mierda removed from en.
*/
const { removeWord } = require("super-profanity");

// You can change the language in which the word will be removed.
removeWord("shit", "es").

/*
shit removed from es.
*/

Custom options

You can use some predefined options to help you through your development! Some of them are:

AutoLog

Automatically displays the detection information.

const { profanity } = require("super-profanity");
profanity(
  "Stick your dentures in your @   ss and go f *c k i n g home laughing.",
  { autoLog: true }
);

/*
{
  badWordLanguage: 'en'
  detectedWord: '@  ss'
  isBadWord: true
  profanityWordRelated: 'ass'
}
*/

HideInformation

Displays or not the information about the detection.

const { profanity } = require("super-profanity");
const result = profanity(
  "Stick your dentures in your @   ss and go f *c k i n g home laughing.",
  { hideInformation: true }
);

console.log(result);

/*
true
*/

Disclaimer

This project was made with the use of two packages:

  1. A modified version of NoSwearingPlease

Lincense:

MIT License

Copyright (c) 2019 Andrew S ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1. TinyLD

License:

MIT License

Copyright (c) 2021 Komodo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Author โœจ


Gabriel C. de Carvalho

super-profanity's People

Contributors

gasegamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

super-profanity's Issues

Checking across languages makes nearly everything bad

My name is bad?

import { changeMainLanguage, profanity } from "super-profanity";
changeMainLanguage("en");
const result = profane("Adam");

result is:

{
  "isBadWord": true,
  "detectedWord": "am",
  "profanityWordRelated": "am",
  "badWordLanguage": "tr"
}

Fails when bundled

Works locally, but the odd way the code tries to load the noswearing module does not work when bundled with esbuild and deployed into an AWS Lambda. (I expect the trouble is when bundling, not the ultimate run environment.)

ERROR	Uncaught Exception 	
{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '/var/task/src/infrastructure/player-api/custom_module/noswearing'\nRequire stack:\n- /var/task/src/infrastructure/player-api/register-player-lambda.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '/var/task/src/infrastructure/player-api/custom_module/noswearing'",
        "Require stack:",
        "- /var/task/src/infrastructure/player-api/register-player-lambda.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
        "    at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
        "    at async start (file:///var/runtime/index.mjs:1137:23)",
        "    at async file:///var/runtime/index.mjs:1143:1"
    ]
}

Help with false positives.

After the fixes which were made until Release 1.1.1, lots of false positives might appear during detection. For example, if the sentence contains the expression but it, the checker will detect the presence of the bad word butt. A quick fix is whitelisting this expression with the whiteListWord function. Therefore, it would be helpful if you could post the false positives and negatives you find in any language, so I can update the profanity list.

Improvement in updateProfanityJson function

I've been using this library in my project and at every start of the application I add some 50 words to be blacklisted, and I noticed that the library will write to the profanity_words json 50 times, that's a lot of time to wait for 50 promises to be fulfilled, sequentially.

I have a suggestion, instead of writing to profanity_words.json every time there is a change, we should keep the user blacklisted/ whitelisted words in memory, which I see is already happening with profanityJson variable. The reason for this is that the users will anyhow have to make the blacklist/whitelist calls at application startup and writing to profanity_words.json is a redundant and expensive operation.

So, my suggestion is to either remove the updateProfanityJson function calls entirely, or have the option for user to configure this behavior. I'm willing to make the changes as well as test them.

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.